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.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comments
Stephen23
on 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
on 13 Nov 2015
Answers (1)
Thorsten
on 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);
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!