Arrays and Logical statements.
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!