Filtering array of custom objects
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Timo Kuchheuser
el 25 de Nov. de 2018
Editada: Sebastian Tilders
el 23 de Jul. de 2022
Hey!
I was wondering if it is possible to implement the filtering of arrays as describes here: Find Array Elements That Meet a Condition for an array holding objects of a custom class.
I have a class with the following property
properties (Access = public)
stages (1,:) EnvelopeStage
end
An EnvelopeStage object has the following properties
properties (GetAccess = public, SetAccess = public)
name string
duration double {mustBeFinite, mustBeNonnegative, mustBeLessThanOrEqual(duration,1)} = 0
target_level double {mustBeFinite, mustBeNonnegative, mustBeLessThanOrEqual(target_level,1)} = 0
end
What would be the smartes way (besides iterating over the array) to filter by name?
Is there a way to implement or use a function that yields the elemtens with code like this:
stages(stages.name == 'foo');
Thank you very much
Tim
0 comentarios
Respuesta aceptada
Honglei Chen
el 26 de Nov. de 2018
You can probably try
idx = arrayfun(@(x)strcmp(x.name,'foo'),stages);
stages(idx);
HTH
2 comentarios
Sebastian Tilders
el 23 de Jul. de 2022
Editada: Sebastian Tilders
el 23 de Jul. de 2022
This does not work, as it does not return indexes. It return strcmp results. stages(idx == 1) works for me.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!