i am working with huge data (1800000x39 mtrix) in MATLAB. I have to extract a block of matrix from certain interval out of the this large matrix. How can i concatenate the matrix from each iteration.
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
data=('test.txt'); M=importdata(data);
for i=1:100 m1=M(i:i+3,1:3) end How can i concatenate the matrix generated by each iteration? Thank you in advance for your help.
2 commentaires
Stephen23
le 13 Nov 2015
Concatenating arrays within loops is a very poor scripting concept in MATLAB. It leads to very slow code due to the repetitive memory allocations required. You can avoid this by preallocating the arrays, or even better learning to write vectorized code. For an explanation of array preallocation:
Mukunda Tamang
le 13 Nov 2015
Réponses (1)
Thorsten
le 13 Nov 2015
First generate an index of all the rows you need, an then use this index to get the small matrix m:
idx = cell2mat(arrayfun(@(i) ([i:i+3]), 1:100, 'UniformOutput', false));
m = M(idx, 1:3);
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!