Clear Filters
Clear Filters

How to use switch statement with list box?

11 views (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!