フィルターのクリア

How to use switch statement with list box?

3 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2023 年 11 月 4 日
回答済み: Walter Roberson 2023 年 11 月 4 日
Hi! :)
Please see the attached code.
What I dont understand is what I have done wrong here . I think the code runs when I dont click cancel on the listbox but when I choose cancel from the listbox, I get error.
Have I done something wrong writing if statement within otherwise and using empty as an option there..?
Please run the code with for instance samlet_akivitet=0.5 and temperature =30 ;
Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 11 月 4 日
When you ask to cancel then indx is empty, []. The empty matrix is not considered to be a scalar -- a scalar is 1 x 1 but [] is 0 x 0. And when you ask to switch on something, you need to switch on a scalar or on a character vector
You need to re-order your code. After the listdlg() test
if ~tf
osmotic_pressure= [];
disp('You have not chosen any value for ME.')
error_osm=1;
return
end
Now you can switch() indx and be certain that indx is a scalar.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by