Arrays and Logical statements.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all!
I wrote a code, using logical statements (including &&) to in a if else statement, where you input a number, and depending the number, it outputs a different value. To test the code, I want to use an array of different numbers as the input. I tried the logical function with the array, but it gives an error saying
"Error using logical
Conversion to logical from cell is not possible."
Anyone know what to do to fix this? Thanks
0 comentarios
Respuestas (1)
Walter Roberson
el 1 de Abr. de 2018
You used a cell array to hold the numbers instead of a numeric array. For example {1 2 3} is a cell array but [1 2 3] is a numeric array.
Note: if you used inputdlg(), then the result of that is a cell array of character vectors, not numeric. Also, if you used a uicontrol style 'edit' then the String property of that could be either character vector or cell array of character vectors. If you are dealing with either of those you should probably use str2double() on your input. Just be sure to check whether the result of str2double() is NaN, which would indicate that the input was not in valid format to be a single number.
0 comentarios
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!