How to properly pass values in Guide?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Alexandru Lapusneanu
el 26 de Feb. de 2018
Comentada: Alexandru Lapusneanu
el 26 de Feb. de 2018
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 26 de Feb. de 2018
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
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
and also http://www.mathworks.com/help/matlab/math/parameterizing-functions.html as you should probably not be using global.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!