フィルターのクリア

Conditionals in Matlab app.designer?

6 ビュー (過去 30 日間)
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras 2021 年 1 月 20 日
コメント済み: Adam Danz 2021 年 1 月 20 日
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.
This is the code I have made, but it doesn`t work
When I choose 'b' in the dropmenu and the click the button, this error appears:
What am I doing wrong in the conditional? Is there any way of achieving what I am looking for?
Thanks!

採用された回答

Adam Danz
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 件のコメント
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras 2021 年 1 月 20 日
I did the following. It works but I don't know which solution would be better, and if this solution would cause any error in the future.
I have defined "coc" as a private variable to use it along the code, and in the dropmenu's callback I defined the following:
And then, instead of the previous conditional that I have posted in the previous question, I did this:
And it works perfectly. But I'm not sure if it's the best option out there
Adam Danz
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 ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by