Problem with radiobutton GUI

3 visualizaciones (últimos 30 días)
Andreas Sitorus
Andreas Sitorus el 4 de Abr. de 2020
Editada: Andreas Sitorus el 5 de Abr. de 2020
I'm having difficulties on using the radiobutton in GUI. I'm trying use 4 radio button in one button group to assign value for a variable called Cstern and use it to another function. The tag for each button are NS, PG, VS, and US,here is the code that i write:
% --- Executes when selected object is changed in uibuttongroup1.
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
switch (get(eventdata.NewValue, 'Tag'));
case 'NS'
Cstern=0;
case 'PG'
Cstern=-25;
case 'VS'
Cstern=-10;
case 'US'
Cstern=10;
end
% hObject handle to the selected object in uibuttongroup1
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
.
But then i got an error message like this:
.
>> holtropcalc
Unrecognized function or variable 'Cstern'.
Error in holtropcalc>CALCULATE_Callback (line 835)
C=1+0.11*Cstern;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in holtropcalc (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)holtropcalc('CALCULATE_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
-I haven't change any code in the first part of code that matlab automatically gives.
-'C=1+0.11*Cstern;' is the next function
Is this has to do with passing value from the radio button function to this Cstern function?
Thanks in advance!

Respuestas (1)

Image Analyst
Image Analyst el 5 de Abr. de 2020
Cstern is just used locally and is in scope only in that function. Once that function ends, no other function can see it. If you want some other function to see it, you can attach it to handles in the radio button function
handles.Cstern = Cstern;
then, in the other function:
C = 1 + 0.11 * handles.Cstern;
Or see the FAQ for even more ways: The FAQ
  1 comentario
Andreas Sitorus
Andreas Sitorus el 5 de Abr. de 2020
Editada: Andreas Sitorus el 5 de Abr. de 2020
Thank you for your response Image Analyst, now I understand the concept. But yeah the eror message still shows up. Am i supposed to write the handles in this way:
case 'NS'
handles.Cstern=0; and so on
or should i just insert this line "handles.Cstern = Cstern;" before the switch, befor the end or after the end of the radio button function? I already tried all of it and it doesn't work as well.
I'm still pretty new with matlab especially GUI. So I'm sorry if perhaps my problem here is just a minor newbie errors, but really looking forward for your assistance.

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by