Fields within Cell structures.

조회 수: 2 (최근 30일)
BoostedMan
BoostedMan 2020년 12월 16일
답변: Vasco Lenzi 2020년 12월 17일
I was just trying to find out how to sort by field of a structure. say I have 10 cars that are all:
Car(1).name = 'BMW 3 Series'
Car(1).type = 'Sedan'
Car(1).mpg = 30
Car(1).price = 40,000
Car(1).seats= 5
(but different of course) , how could i sort them after asking a question by, say 20mpg or over, and then take that new list and sort it by price, and so on.

답변 (2개)

James Tursa
James Tursa 2020년 12월 16일
E.g., to sort everything by mpg:
[~,x] = sort([Car.mpg]);
CarMpg = Car(x);
To pick off only those with certain constraints, e.g.
x = [CarMpg.mpg] >= 20;
CarMpg20 = CarMpg(x);

Vasco Lenzi
Vasco Lenzi 2020년 12월 17일
I would use Table instead of Struct
it would make your life sooooo much easier.
Some table workflow example:

커뮤니티

더 많은 답변 보기:  Power Electronics Community

카테고리

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