2

I have two GUIs namesd masir and SetOut
SetOut GUI is a sub GUI for masir(pressing a button on masir will open SetOut) To access the data of masir in SetOut I have these 2 lines of code:

masirGUIhandle = masir;  
masirGUIdata = guidata(masirGUIhandle);  

but running these 2 lines will run the opening function of masir as I work in SetOut(In opening function I have set some initial values for my variables and now I don't want those initial values ,I need changed values for my variables) so I dont want the OpeningFcn of masir GUI to be runned ,I just need to have access to masir data in SetOut What can I do to fix the problem?

Can any one help me about this answer and explain me more?

I use this easy way for data sharing between GUIs
%In the end of OpeningFcn of Main GUI
setappdata(0,'HandleMainGUI',hObject);
%When you want to edit shared data you must get the handle
HandleMainGUI=getappdata(0,'HandleMainGUI');
%write a local variable called MyData to SharedData, any type of data
setappdata(HandleMainGUI,'SharedData',MyData); 
%get SharedData and save it to a local variable called SomeDataShared
SomeDataShared=getappdata(HandleMainGUI,'SharedData'); 
Don't forget to clean up the data shared in the CloseReqFcn of you main GUI
HandleMainGUI=getappdata(0,'HandleMainGUI');
rmappdata(HandleMainGUI,'MySharedData') %do rmappdata for all data shared 
Remember that your GUIs might try to getappdata that doesn't exist, you should    first     test if it does exist
if (isappdata(0,'HandleMainGUI') & isappdata(HandleMainGUI,'MySharedData'))
%get, set or rm appdata
else
%do something else, maybe loading default values into those variables
end  

Tell me more aboute which line of code should be written in MainGUI and which line should be written in SubGUI?
And tell me what does the responser mean by CloseReqFcn?

Sepideh Abadpour
  • 2,550
  • 10
  • 52
  • 88
  • Can you extend the example? It's not really clear what your problem is. – bdecaf Apr 08 '12 at 08:21
  • My question is exactly the same as this question: [link](http://www.mathworks.fr/matlabcentral/answers/338-how-to-pass-data-from-one-gui-to-another)but I need more help because the answer suggested does not work – Sepideh Abadpour Apr 08 '12 at 18:58

1 Answers1

2

Well let me summarize how I see the problem.

You want to read the data from SetOut with out creating it? That's not possible like this as the data will be created when the window is created.

A nice and systematic way around would be doing it object oriented (see Model-View Controller Pattern) You can more or less copy an example from my answer here (Example for Event - Observer)


But if you'd like to stick with your code I also have some ideas:

  • If you don't want the window to show you could set it invisible with set(theGUIhandle,'Visible','off')

  • While the window is not closed you can obtain the data with getappdata(theGUIhandle)

  • If you want the data after the window is closed you need to have a function that stores it outside the window.

Community
  • 1
  • 1
bdecaf
  • 4,652
  • 23
  • 44