Arrays and Logical statements.

5 Ansichten (letzte 30 Tage)
spete
spete am 1 Apr. 2018
Beantwortet: Walter Roberson am 1 Apr. 2018
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

Antworten (1)

Walter Roberson
Walter Roberson am 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.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by