guidata doesn't save my data, why?
조회 수: 2 (최근 30일)
I have a GUI made in GUIDE. I need to store some data within functions and they must be reachable by other callbacks. I am using guidata like the following:
MyData = CalculateMyData(inputs);
handles.DataToSave = MyData;
Later in another Callback I'm trying to get back the data and save it to a file like the following:
SavedData = handles.DataToSave;
However, the field DataToSave no longer exists. I know that the handles and the guidata are not the same structure, therefore I tried the following code as well:
MyGUIData = guidata(gcf());
SavedData = MyGUIData.DataToSave;
Unfortunately this code does not work either. How can I solve this problem? Any help is appreciated. László
Luffy 2012년 7월 5일
편집: Walter Roberson 님. 2012년 8월 13일
I did not exactly understand,but you can try this method:
The data that you want to save in your 1st function,save it to base workspace.
Now that it is saved in base workspace,use it in your 2nd function by.
v = evalin('base','handles.DataToSave');
That Data is now in v,use v in your function where you wnt to.
Just see u hv handles.DataToSave in your base workspace.
Or this should help:
추가 답변 (3개)
Sean de Wolski 2012년 8월 13일
I am guessing that the use of gcf() is what is making this not work. If the figure's HandleVisibility is 'off' or 'callback', gcf() will create a new figure to be the current figure.
To fix it, rather than using gcf, use handles.( Tag of your figure ).