Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to Assign Values from a Struct to a Matrix in a For Loop?

1 回表示 (過去 30 日間)
Rightia Rollmann
Rightia Rollmann 2017 年 3 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
A.B.C = [1 2 3];
A.B.D = [3 4 5];
for k = 1:2
G(k, :) = A.B.C;
G(k, :) = A.B.D;
end
G
G returns:
3 4 5
3 4 5
Why doesn’t it return the following? What is the solution to have a G like the following?
1 2 3
3 4 5

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 3 月 4 日
G(1,:) = A.B.C;
G(2,:) = A.B.D;
No loop.
  2 件のコメント
Rightia Rollmann
Rightia Rollmann 2017 年 3 月 4 日
編集済み: Rightia Rollmann 2017 年 3 月 4 日
What if instead of two fields, I had 50 fields?
Isn't there any way to use a for loop to dynamically make a matrix out of vectors stored in a struct?
Walter Roberson
Walter Roberson 2017 年 3 月 6 日
G = cell2mat( struct2cell(A.B) );

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by