variables are not saved in workspace after function.
Mostrar comentarios más antiguos
function = demo()
figure('WindowButtonDownFcn',@callBack)
function callBack(hObject,~)
mousePos=get(hObject,'CurrentPoint');
x = mousePos(1)
y = mousePos(2)
So when I am lunching the function x and y are ploting in 'Command Window', but they aren,t saved in workspace.
pleas Help!!!
Respuestas (4)
dpb
el 3 de Jun. de 2019
1 voto
It can't--you don't return anything. Read about functions at
Stephen23
el 4 de Jun. de 2019
You need to explicitly pass those variables between workspaces, exactly as the MATLAB documentation describes:
Avoid using global and assignin. If you are sensibly writing your own GUI code then I recommend that you use nested functions for passing data between callbacks, because these are simple and intuitive:
function [x,y] = demo()
x = [];
y = [];
fgh = figure('WindowButtonDownFcn',@callBack)
waitfor(fgh)
function callBack(hObject,~)
mousePos=get(hObject,'CurrentPoint');
x = mousePos(1)
y = mousePos(2)
end
end
luka gvichiani
el 6 de Jun. de 2019
0 votos
5 comentarios
Walter Roberson
el 6 de Jun. de 2019
[x, y] = demo();
luka gvichiani
el 6 de Jun. de 2019
Walter Roberson
el 6 de Jun. de 2019
ans is only ever one variable. ans is only updated when you do a calculation but do not assign the results to a location. The only way you could get ans out of that is if you did not follow my instructions -- if you ran the code as just
demo
or if you clicked the green run button. You need to go down to the command window and type in
[x, y] = demo();
luka gvichiani
el 6 de Jun. de 2019
Stephen23
el 7 de Jun. de 2019
luka gvichiani
el 6 de Jun. de 2019
0 votos
Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!