matrix indexing and creating a new matrix with new size
Ältere Kommentare anzeigen
Dear experts, I hope somebody can help me. I have a n*4 matrix. In a loop I want to index some rows (the range is not fixed) from column 1 and put them in a new matrix with separate columns. I guess since the size of rows are not the same, Matlab gives me the mismatch dimension error for new matrix! Any solution? Thanks in advance Sobhan
Akzeptierte Antwort
Weitere Antworten (3)
Wayne King
am 6 Jun. 2012
0 Stimmen
How about using a cell array? Beyond that I think you will need to give us a little MATLAB example to illustrate your issue.
1 Kommentar
Sobhan
am 6 Jun. 2012
Christoph
am 6 Jun. 2012
Hi Sobhan,
as Wayne said, an example might be helpful. Nevertheless you might use:
X_new(:,end+1) = [X_old(:,i); zeros(size(X_new, 1) - size(X_old, 1),1)];
in your loop as long as the length of the old matrix is shorter or equal as the length of the new one. But waynes answer is the "politcally correct" one.
Sobhan
am 8 Jun. 2012
0 Stimmen
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!