Find index of a structure with multiple conditions of multiple fields

19 Ansichten (letzte 30 Tage)
Hi! I have a structure array with some fields and would love to know how to find the index (the line) of that structure that match conditions from the differents fields of the same structure array.
To explain, let say I have this structure :
S.liste.a = linspace(1,30,5)
S.liste.b = linspace(1,60,5)
S.liste.c = linspace(1,80,5)
I want to know the index of S.liste that fits conditions like :
S.liste.a < 10 && S.liste.b < 50 && S.liste.c < 60
I know this conditions have no sens with this data but it's just an example.
Can I do this without using loops?
Thanks a lot!! :)
  2 Kommentare
Stephen23
Stephen23 am 7 Okt. 2022
"and would love to know how to find the index (the line) of that structure..."
All of your structures are scalar, so have only one "line".
"...that match conditions from the differents fields of the same structure array"
All of your structures are scalar, rather trivial size arrays.
Or are you mixing up the size of a structure with the sizes of its fields?
Amaury
Amaury am 7 Okt. 2022
Wow thank you for your quick reply! It was much easier than I thought ahah
I think I was wrong with the sort of structure, finally I get what I needed with your code and using "[ ]" because my structure was divided in fields...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 7 Okt. 2022
Bearbeitet: Stephen23 am 7 Okt. 2022
S.liste.a = linspace(1,30,5);
S.liste.b = linspace(1,60,5);
S.liste.c = linspace(1,80,5);
X = S.liste.a<10 & S.liste.b<50 & S.liste.c<60
X = 1×5 logical array
1 1 0 0 0

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by