Arrays and Logical statements.
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 1 Apr 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 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!