Can anyone help me figure out the preallocation of the unknown matrix which no. of rows changing in every cycle? Thank in advance
1 次查看(过去 30 天)
显示 更早的评论
close all; clc;
tic
p=dir('*.txt');
nFiles=numel(p);
A_cat=[]; % A_cat=zeros(500000,30);
for k=1:nFiles
A=dlmread(p(k).name);
disp(size(A_cat)); %% you can check the no. of rows is increasing
%A_cat=[A_cat;A]; %% every cycle, matrix changes its size!!!
A_cat=vertcat(A_cat,A);
end
toc
0 个评论
采纳的回答
KSSV
2021-2-23
编辑:KSSV
2021-2-23
close all; clc;
tic
p=dir('*.txt');
nFiles=numel(p);
A_cat=cell(nFiles,1); % A_cat=zeros(500000,30);
for k=1:nFiles
A=dlmread(p(k).name);
disp(size(A_cat)); %% you can check the no. of rows is increasing
%A_cat=[A_cat;A]; %% every cycle, matrix changes its size!!!
A_cat{k} = A;
end
A = vertcat(A_cat{:}) ;
toc
5 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!