Using listbox in MATLAB GUI
21 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Avinav Kumar
il 14 Mar 2021
Commentato: Avinav Kumar
il 16 Mar 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 Commenti
Risposta accettata
Image Analyst
il 14 Mar 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 Commenti
Image Analyst
il 15 Mar 2021
Set a breakpoint and just step through until you find the cause of the error.
Più risposte (0)
Vedere anche
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!