Check if all values in cell array are 'on'
Mostrar comentarios más antiguos
I created an array of objects in app designer. They're all images.
images=[app.Image1,app.Image2,.......,app.ImageX];
now I get their visible property
check=get(images,'Visible');
that gives me a cell array of 'on' and 'off' values. I want to check if all the values in the array are 'on'. How do I do that? I tried combining it into a matrix, but got errors.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 26 de Abr. de 2021
Try this:
>> ca = {'on', 'on', 'on'}
ca =
1×3 cell array
{'on'} {'on'} {'on'}
>> allOn = all(ismember(ca, {'on'}))
allOn =
logical
1
>> ca = {'on', 'on', 'off'}
ca =
1×3 cell array
{'on'} {'on'} {'off'}
>> allOn = all(ismember(ca, {'on'}))
allOn =
logical
0
3 comentarios
Vojtech Siler
el 26 de Abr. de 2021
Image Analyst
el 27 de Abr. de 2021
You changed something. My code works. I don't have 34 lines in my code. I had only 2 lines and they worked. You don't need anonymous functions, strcmp(), cellfun(), etc. All you need is the single line of code I gave you that calls ismember().
Vojtech Siler
el 27 de Abr. de 2021
One easy way to do this is to use a string.
A = {'on', 'on', 'on'};
all(A == "on")
2 comentarios
Vojtech Siler
el 26 de Abr. de 2021
DGM
el 27 de Abr. de 2021
It depends what version you have. This usage with the double quoted string needs R2016b to work (IIRC). At least it doesn't work for me in R2015b.
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!