Assigning a value to certain indexed elements of a struc variable

조회 수: 1 (최근 30일)
z8080
z8080 2018년 3월 11일
댓글: z8080 2018년 3월 12일
I am trying to assign a certain value to several elements of an indexed structure:
indices = 1:3
people(indices).gender ='m'
..but get the error
"Expected one output from a curly brace or dot indexing expression, but there were 3 results."
Is this a limitation of how Matlab can work with structures, or am I making a mistake in how I am using these variables?
Is this the (still not implemented) enhancement described in this other thread reporting the same error?
Thanks for any help! I am using 2016b.

채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 11일
[people(indices).gender] = 'm';
  댓글 수: 6
Walter Roberson
Walter Roberson 2018년 3월 12일
Note that Jos's solution only works for the initial creation of the output, not for setting a field within an existing structure
z8080
z8080 2018년 3월 12일
Thanks Jos, this is good to know as well!

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by