How to use switch statement with list box?

4 visualizzazioni (ultimi 30 giorni)
Muazma Ali
Muazma Ali il 4 Nov 2023
Risposto: Walter Roberson il 4 Nov 2023
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

Risposte (1)

Walter Roberson
Walter Roberson il 4 Nov 2023
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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by