Conditionals in Matlab app.designer?
조회 수: 6 (최근 30일)
이전 댓글 표시
I'm trying to design the following app. The user choose one of the following values in the dropmenu and the clicks the button. If the dropmenu is visible for the user AND its value is 'b', a 40 appears on the white window. If not, a 10 appears in the white window.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/494964/image.png)
This is the code I have made, but it doesn`t work
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/494969/image.png)
When I choose 'b' in the dropmenu and the click the button, this error appears:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/494974/image.png)
What am I doing wrong in the conditional? Is there any way of achieving what I am looking for?
Thanks!
댓글 수: 0
채택된 답변
Adam Danz
2021년 1월 20일
Avoid using "==" to test equaltify for non-numeric and non-scalar values.
For strings / character arrays, use,
if strcmp(app.menu1.Value, 'b') && strcmp(app.menu1.Visible,'on')
or use strcmpi() to ignore case.
If the problem persists, share the values in app.menu1.Value.
댓글 수: 2
Adam Danz
2021년 1월 20일
Its not the best solution because it makes the same mistake I pointed out in my answer.
Also, if coc is binary (true|false), then you don't need app.coc==1. You ony need
if strcmp(app.menu1.Valuem,'b') && app.coc
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!