How to properly pass values in Guide?

조회 수: 1 (최근 30일)
Alexandru Lapusneanu
Alexandru Lapusneanu 2018년 2월 26일
댓글: 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.

추가 답변 (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