How to properly pass values in Guide?

1 回表示 (過去 30 日間)
Alexandru Lapusneanu
Alexandru Lapusneanu 2018 年 2 月 26 日
I'm trying to pass some values to a "main function" so when I press the button simulate it should take account of the values and also should call a matlab script, but when I'm pressing the button ,nothing happens.
function minutsc_Callback(hObject, eventdata, handles)
% hObject handle to minutsc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
min=str2double(get(hObject,'String'))
function orasc_Callback(hObject, eventdata, handles)
% hObject handle to orasc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ora=str2double(get(hObject,'String'))
...
And the main function
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global tspan
tspan = get(handles.edit32, 'value');
global y0
y0(1,1)=get(handles.edit29, 'value');
y0(2,1)=get(handles.edit26, 'value');
y0(3,1)=get(handles.edit27, 'value');
y0(4,1)=get(handles.edit28, 'value');
y0(5,1)=get(handles.edit30, 'value');
y0(6,1)=get(handles.edit31, 'value');
global an
an=get(handles.ancall, 'value');
global luna
luna=get(handles.lunasc, 'value');
global zi
zi=get(handles.zicall, 'value');
global ora
ora=get(handles.orasc, 'value');
global min
min=get(handles.minutsc, 'value');
global sec
sec=get(handles.seccall, 'value');
global m
m=get(handles.Masaedit, 'value');
global A
A=get(handles.Arias, 'value');
orbit

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 26 日
Your line
min=str2double(get(hObject,'String'))
calculates a value, and assigns it to a variable named min inside the minutsc_Callback workspace. Then, because there is no semi-colon at the end of the expression, it will display the output in the form
min =
.... some value here
After that, the function reaches the end and returns, destroying the local workspace. The only practical effect of this is to have displayed the value of the variable to the screen.
I recommend that you read
and also http://www.mathworks.com/help/matlab/math/parameterizing-functions.html as you should probably not be using global.
  1 件のコメント
Alexandru Lapusneanu
Alexandru Lapusneanu 2018 年 2 月 26 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by