필터 지우기
필터 지우기

Query data from 1xn struct

조회 수: 2 (최근 30일)
Le Vu Bao
Le Vu Bao 2019년 7월 14일
편집: Le Vu Bao 2019년 7월 15일
Hi, I have a 1x3 struct just like below:
% Q(1)
Q(1).name='carrot';
Q(1).price=200;
Q(1).number=1000;
%Q(2)
Q(2).name='banana';
Q(2).price=200;
Q(2).number=2000;
%Q(3)
Q(3).name='apple';
Q(3).price=900;
Q(3).number=200;
How can I quickly query "price" of "banana" or "number" of "apple"?
Is there any shorcut beside manually gathering name to string array (Q.name returns scattering outputs)

채택된 답변

Rik
Rik 2019년 7월 14일
The table data type is probably a better choice for your usage. Then you can also easily index.
  댓글 수: 2
madhan ravi
madhan ravi 2019년 7월 14일
True using struct2table()
Le Vu Bao
Le Vu Bao 2019년 7월 15일
편집: Le Vu Bao 2019년 7월 15일
oh,how silly I am. Thank you.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by