Arrays and Logical statements.

5 ビュー (過去 30 日間)
spete
spete 2018 年 4 月 1 日
回答済み: Walter Roberson 2018 年 4 月 1 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 1 日
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.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by