使用xlswrite保存数值数据

时间:2015-06-28 19:18:20

标签: matlab export-to-excel

您好我想从循环内的操作中保存数值数据。让我们看看我的细分示例:

    clear all, clc;

a=1:35;
A = arrayfun( @(x) sprintf( '%04d', x ), a, 'UniformOutput', false );
I = cellfun( @(b) imread( ['C:Teste/' b '/c1/' b '.png'] ), A, 'UniformOutput', false );

for i = a
    % Gaussian Filter
    W = fspecial('gaussian',[10,10],2);
    J = imfilter(I,W);

    % Finding Circular objects -- Houng Transform
    [centers, radii, metric] = imfindcircles(J,[5 10], 'Sensitivity',0.93,'Edge',0.27); 

    idx_mask = ones(size(radii));

    min_dist = 2; % relative value.
    for i = 2:length(radii)
        cur_cent = centers(i, :);
        for j = 1:i-1
            other_cent = centers(j,:);
            x_dist = other_cent(1) - cur_cent(1);
            y_dist = other_cent(2) - cur_cent(2);
            if sqrt(x_dist^2+y_dist^2) < min_dist*(radii(i) + radii(j)) && idx_mask(j) == 1
                idx_mask(i) = 0;
                break
            end
        end
    end

    idx_mask = logical(idx_mask);
    centers_use = centers(idx_mask, :);
    radii_use = radii(idx_mask, :);
    metric_use = metric(idx_mask, :);

    viscircles(centers_use, radii_use,'EdgeColor','b');
    a=length(centers_use)
end

所以重点是将35个结果保存在xls文件的一列中。

我试图这样做,但只有循环的最后一个元素打印在exel文件中......

filename = 'testdata.xlsx';
A = vertcat('Test', 'Results', num2cell(a'));
sheet = 1;
xlRange = 'F03';
xlswrite(filename,A,sheet,xlRange)

可以请任何人帮助我吗?我知道有很多与此问题相关的问题,但没有一个问题涉及我的问题......

我将留下一张图片进行测试: Sample Image in order to run the algorithm and replicate my situation

提前多多感谢。 约翰

1 个答案:

答案 0 :(得分:2)

正如@excaza所说,你需要扩展HashSet

b