필터 지우기
필터 지우기

separate matrices out of struct

조회 수: 1 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2017년 1월 11일
댓글: Stephen23 2017년 1월 11일
I have a struct having matrices of B1, B2, and B3. I want to make three separate matrices out of them available in the Workspace automatically with the help of a loop. How?
S = struct('B1',[1 2;3 4],'B2', [5 6; 7 8], 'B3', [9 10; 11 12] )
  댓글 수: 1
Stephen23
Stephen23 2017년 1월 11일
"I want to make three separate matrices out of them available in the Workspace automatically with the help of a loop"
Here is why that would be a very bad idea:

댓글을 달려면 로그인하십시오.

채택된 답변

Jos (10584)
Jos (10584) 2017년 1월 11일
Why? Apparently the three matrices are related. Keeping them in a single struct shows this relationship. If you need to access one of them you can easily do this using assignment operations
X = S.B1
or dynamically
k = 2
field = sprintf('B%d',k)
X = S.(field)

추가 답변 (1개)

Rightia Rollmann
Rightia Rollmann 2017년 1월 11일
Thanks, man! You not just answered it, but perfected the question too!

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by