필터 지우기
필터 지우기

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?

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by