Check if a value from a dropdown menu is in a struct

1 vue (au cours des 30 derniers jours)
Stine Sig
Stine Sig le 19 Juin 2019
Modifié(e) : Stephen23 le 19 Juin 2019
Hi. I have the following code, where I struggle because no member is detected.
My 'idx' just return a 1*80 logical containing zeros. When I debug I can see that 'a' contains 16 doubles with the number 67.2022 and 'b2' is a double variable with the number 67.2022. So the are both the same type.
a = [app.sortedS.SliceLocation]; % this is a column from a struct containing different double values
b = app.dd_SliceLocation.Value; % this is a value from a dropdown box
b2 = str2double(b);
for ii = 1:length(a)
idx(ii) = ismember(b2,a(ii));
end
imageT = app.sortedS.Image(idx) % Image is a column in the same struct (sortedS) as 'a'.
Hope you are able to help!

Réponse acceptée

Stephen23
Stephen23 le 19 Juin 2019
Modifié(e) : Stephen23 le 19 Juin 2019
Most likely those values are not exactly the same because you are trying to compare floating-point numbers, which is never a good idea, as has been discussed countless times already on this forum:
You can easily resolve this using ismembertol
or compare the absolute difference against a tolerance:
abs(A-B)<tol

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by