How to use switch statement with list box?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!