Using listbox in MATLAB GUI
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Avinav Kumar
am 14 Mär. 2021
Kommentiert: Avinav Kumar
am 16 Mär. 2021
Hi,
I have a MATLAB GUI with listbox having numbers - 1,2, 3, 4 , 5, 6
I need to select one number say using listbox and then multiply this number with a number which users enter in textbox and feed the answer in another textbox.
How to go about this.
Thank you.
3 Kommentare
Akzeptierte Antwort
Image Analyst
am 14 Mär. 2021
Try this
% Get value from edit field 1
b = str2double(handles.edit1.String);
% Get list of everything in the listbox.
listboxItems = handles.listbox1.String;
% Get the index of the item they selected.
selectedItem = handles.listbox1.Value;
% Turn that selection into a double number.
listboxNumber = str2double(listboxItems{selectedNumber})
% Do the multiplication.
c = b * listboxNumber;
% Send the result into edit field 3.
handles.edit3.String = sprintf('%.4f', c);
Of course you should make it more robust by checking that the listbox actually has something in it, that they have actually selected one of the items, that the item is really a number, and that the edit field 2 has a valid number in it. I'm leaving all those validation checks up to you.
7 Kommentare
Image Analyst
am 15 Mär. 2021
Set a breakpoint and just step through until you find the cause of the error.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!