Problem with radiobutton GUI
2 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Image Analyst
on 5 Apr 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
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!