Why, when doing a for loop to form a column from an array, does it give me 0 values except for the last element?
3 ビュー (過去 30 日間)
古いコメントを表示
Matias Quezada Cepeda
2021 年 2 月 18 日
コメント済み: Matias Quezada Cepeda
2021 年 2 月 18 日
I need to form a column from a matrix, so that each row becomes a column, for example if I have a matrix of size mx3 [X Y Z, A B C, 1 2 3], I need it to be (3 * m) x1 [X, Y, Z, A, B, C, 1,2,3], I tried doing this with a double for loop, but it only returns zeros except for the last element. Following the previous example it would be [0,0,0,0,0,0,0,0,3]
[m,n]=size(IncECEF);
N=n;
M=m;
for I=1:N;
for Q=1:M;
Lo(N+3*(M-1),1)=IncECEF(M,N);
end
end
I don't understand why it happens, I think that each iteration overwrites the Lo matrix, writing the element of each iteration and thus deleting the previous ones, but I don't know if that is the cas
0 件のコメント
採用された回答
Fangjun Jiang
2021 年 2 月 18 日
編集済み: Fangjun Jiang
2021 年 2 月 18 日
most likely, change to
Lo(I+3*(Q-1),1)=IncECEF(Q,I)
And do you know this?
A=magic(5);
B=A'
C=B(:)
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!