How to properly pass values in Guide?

1 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by