我需要一种方法来保存通过for循环生成的数据。简单地解释一下,首先我在第二次迭代中生成一个矩阵5 * 10,重复该过程并生成另一个矩阵5 * 10(**请注意也许有些行需要为空)(我的意思是在第二次迭代中row3为空),第二个矩阵应该连接第一个并生成5 * 20矩阵。这可能在excel中。但我需要更快的方法来保存数据? table / dataset / ...中的哪一个可以使用????
[data,header] = xlsread('E:\TEST\chozen_font_data.xlsx','font');
font_data = data(:,1);
a = 'C:\Users\S.R.P\Desktop\ouput';
A = dir(fullfile(a));
isub = [A(:).isdir];
nameFolds = {A(isub).name}';
nameFolds(ismember(nameFolds,{'.','..'})) = [];
for n_fol = 1:numel(nameFolds)
name_sub_fold = dir(fullfile(a,nameFolds{n_fol},'*.png'));
for n_sub = 1: numel( name_sub_fold )
[~,~,image] =
imread(fullfile(a,nameFolds{n_fol},name_sub_fold(n_sub).name));
image=im2bw(image);
[ image ] = Crop_AroundAllComponent( image );
name_font = regexprep(name_sub_fold(n_sub).name,'[^0-9]','');
co = find( font_data == str2num( name_font));
area = area_calculation( image );
md = matrix_density_calculation( image );
[ num ] = DisconnectedComponent_calc( image );
d={area,md,num};
[s,m] = xlswrite('E:\TEST\chozen_font_data.xlsx', d, 'font',
strcat('GB',num2str(co)));
end
end
答案 0 :(得分:0)
要在matlab中连接2个矩阵,您可以使用方括号连接表示法。像这样:
row1 = zeros(10, 5); % 10 by 5 row
row2 = ones(10, 5); % another 10 by 5 row
total = [row1; row2]; % 20 by 5 combination
如果您想使用for循环执行此操作,则可以在每次迭代时添加一个新行。例如:
start = 0;
end = 5;
result = [];
for i = start:end
row = ... % get the new row here
result = [result; row];
end