Import variables from .m file to gui

4 visualizaciones (últimos 30 días)
MrMedTech
MrMedTech el 6 de Abr. de 2016
Comentada: Stephen23 el 8 de Abr. de 2016
Hello together, I just got a problem in my code.
i created a gui which calls a sub program.
This works fine so now I added a table in my gui.
I made a calculation which is done many times and always gives me an output which I want to display every single time in the table. So I saved the Result in a variable (2x1 Matrix) and I want to give it the gui for displaying. Am I right that the gui has an extra workspace and I have to put my variable anyway in this extra ws? Thx 4 your help

Respuestas (2)

Orion
Orion el 6 de Abr. de 2016
Editada: Orion el 6 de Abr. de 2016
Hi there are several ways to store a data in a gui.
You can use getappdata/setappdata.
a = 1;
setappdata(gcf,'a',a);
clear a;
a = getappdata(gcf,'a');
you can also use the userdata property.
h.a = 1;
h.b = 2;
set(gcf,'Userdata',h);
clear h;
h = get(gcf,'Userdata')
You can also use the function guidata.
  1 comentario
Stephen23
Stephen23 el 8 de Abr. de 2016
Philipp Weinhardt's "Answer" moved here:
So I've done this:
figHandle = findall(0,'Name','main_gui');
setappdata(figHandle,'left_ph',left_phi);
so phi is the variable I want to give to my gui.
And within my gui I've done this:
left_phi=getappdata(figHandle,'left_ph'); left_ph=num2str(left_phi); set(handles.table,'String',left_ph); guidata(hObject,handles);
So this doens't work. Do you know what#s still wrong?
Thank you very much for your advice.

Iniciar sesión para comentar.


MrMedTech
MrMedTech el 7 de Abr. de 2016
Hi
thx for your answer.
Can I just use setappdata and getappdata in a function that is not part of the gui? Because I have to use setappdata in my subprogram and getappdata within my gui? Or am I wrong?
  1 comentario
Orion
Orion el 7 de Abr. de 2016
You can use this functions anywhere.
You just need to know the handle of your figure, which is the first argument to give to those two functions.
If you don't have it, you can find it using findall.
For example, if your gui is named "MyGui".
figHandle = findall(0,'Name','MyGui');
a = getappdata(figHandle,'a');

Iniciar sesión para comentar.

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!

Translated by