How to Create a Column Vector of a Field of a Struct?

조회 수: 12 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2017년 3월 1일
편집: Stephen23 2017년 3월 1일
How to create column vectors out of B (i.e., D = [10;20;30]) and C (i.e., E = [100;200;300])?
A(1).B = 10;
A(2).B = 20;
A(3).B = 30;
A(1).C = 100;
A(2).C = 200;
A(3).C = 300;

채택된 답변

Jan
Jan 2017년 3월 1일
편집: Jan 2017년 3월 1일
D = [A.B];
E = [A.C];
This is the short for of:
[A(:).B]
which has the advantage, that the intention is more obvious during reading.
  댓글 수: 2
Rightia Rollmann
Rightia Rollmann 2017년 3월 1일
Splendid! Thanks!
Stephen23
Stephen23 2017년 3월 1일
편집: Stephen23 2017년 3월 1일
This syntax is explained in the documentation:
PS: the question asks for a column vector, and the answer above gives a row vector. Either transpose, or use vertcat:
D = vertcat(A.B);

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

추가 답변 (0개)

카테고리

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