Problem with radiobutton GUI
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Image Analyst
2020 年 4 月 5 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!