Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
Rightia Rollmann
Rightia Rollmann am 4 Mär. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Walter Roberson
Walter Roberson am 4 Mär. 2017
G(1,:) = A.B.C;
G(2,:) = A.B.D;
No loop.
  2 Kommentare
Rightia Rollmann
Rightia Rollmann am 4 Mär. 2017
Bearbeitet: Rightia Rollmann am 4 Mär. 2017
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?

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by