how to use three pop-up menu to get result in a screen(GUI, using guide)

1 visualización (últimos 30 días)
Hello,
i have a school project i need to create a unit conversion. i did the code but it did not show the result on the screen.
i'm not sure what i did wrong, if possible please check the code i will attach it.
thanks in advance for the help.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 12 de En. de 2022
@Tahani Alajmi - when you launch the GUI and press the convert button, you will see an error in the console window:
Index in position 1 exceeds array bounds (must not exceed 4).
Error in Convert_W>convert_Callback (line 108)
mainList = string( mainList_options{'temperature','angle','length','mass'} );
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Convert_W (line 20)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Convert_W('convert_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
What is the intent of this line of code (which is unused)?
mainList = string( mainList_options{'temperature','angle','length','mass'} );
The mainList_options is already a cell array with these four string values, so it isn't clear what you are attempting here. I would recomment removing this line and those for the innerList1 and innerList2 because they are incorrect and unused. More errors will follow though with the code that tries to compare string values using the == operator. This cannot be used for strings, and instead strcmp or strcmpi can be used instead. That will help, but you still need to figure out what you are trying to do with
if mainList_options=='temperature'
Remember, mainList_options is a cell array of the options from your drop-down control. I think that you want to use the
mainList_value = handles.mainList.Value;
which should be the index to the selected item in the list. In that case, your code would become
if strcmp(mainList_options{mainList_value},'temperature')
Try doing the above for each of your string comparisons to see if that gets the result you are expecting.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by