필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

one Structure Aceess Problem

조회 수: 1 (최근 30일)
ar fa
ar fa 2015년 6월 14일
마감: MATLAB Answer Bot 2021년 8월 20일
I have these below codes:
a(1).x = [5 9];
a(2).x = [4 41];
a(3).x = [7 0];
a(4).x = [23 45];
a(2:3).x(1);
After running these codes, I encountered to below Error:
Scalar index required for this type of multi-level indexing.
Please help me to access to "a(2:3).x(1)" as [4 7].
Thanks

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 14일
MATLAB doesn't allow that.
In the particular case that the vectors are the same size for the structure members, you can use
t = vertcat(a(2:3).x);
t(:,1)
If they are not the same size then
cellfun(@(C) C(1), {a(2:3).x})
  댓글 수: 1
ar fa
ar fa 2015년 6월 15일
Thanks Walter Roberson

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by