Arrays have incompatible sizes for this operation error while checking dropdown.value not equal to a char value
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Govind Sankar Madhavan Pillai Ramachandran Nair
el 16 de Jul. de 2024 a las 13:05
Comentada: Voss
el 16 de Jul. de 2024 a las 13:41
I have created an app in appdesigner and it has a dropdown. And I check the value of this dropdown to a string value.
function SelectBatteryDropDownValueChanged(app, event)
if app.SelectBatteryDropDown.Value ~= 'none'
end
end
'none' is one of the values initialised to the dropdown. Now a select a value from the dropdown I expect the program to check first if the value is not equal to 'none' and if true execute some code. But It is giving an error :
Arrays have incompatible sizes for this operation.
This doesnt make any sense since both 'none' and app.SelectBatteryDropDown.Value are of type char, I checked to make sure. Yet this error is coming. Why is that? How can I fix this. Thank you.
0 comentarios
Respuesta aceptada
Voss
el 16 de Jul. de 2024 a las 13:14
Editada: Voss
el 16 de Jul. de 2024 a las 13:19
Don't use == or ~= to compare character arrays, use strcmp, i.e.:
if ~strcmp(app.SelectBatteryDropDown.Value,'none')
because == and ~= perform element-by-element comparison (just as they do with numeric arrays), which in the case of comparing character arrays, is comparing character by character, e.g.:
'some' == 'none' % compares each character in 'some' to the corresponding character in 'none'
'ok' == 'none' % cannot element-wise compare a two-element character vector with a four-element one
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings 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!