composing small matrices to a large matrix inside a for loop in Matlab -
composing small matrices to a large matrix inside a for loop in Matlab -
suppose have function has output, including numbers , matrices as
[a,a,b,n,m] = func(file) the file input differs each time , func read within loop for. matrix b has 2 columns variable rows depends on input file , computation within func. save these matrices b each time in output. number of iteration fix, 10.
for loop this
for i=1:10 ..... %// here reads name of input file differs each iteration [a,a,b,n,m] = func(file) ..... end is there suggestion?
use cell array:
b_all = cell(1, 10); i=1:10 % here reads name of input file differs each iteration [a,a,b,n,m] = func(file); b_all{i} = b; % go on calculation here end; if want merge them in end (i.e. have single matrix 2 columns):
b_merged = vertcat(b_all{:}); matlab for-loop matrix
Comments
Post a Comment