guidata doesn't save my data, why?

3 ビュー (過去 30 日間)
László Arany
László Arany 2012 年 7 月 5 日
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:
function MyFunction(input1,input2,...,inputN)
MyData = CalculateMyData(inputs);
handles.DataToSave = MyData;
guidata(gcf(),handles)
end
Later in another Callback I'm trying to get back the data and save it to a file like the following:
function SaveData(handles)
SavedData = handles.DataToSave;
dlmwrite(MyFile,SavedData,'\t')
end
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:
function SaveData(handles)
MyGUIData = guidata(gcf());
SavedData = MyGUIData.DataToSave;
dlmwrite(MyFile,SavedData,'\t');
end
Unfortunately this code does not work either. How can I solve this problem? Any help is appreciated. László

採用された回答

Luffy
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.
assignin('base','handles.DataToSave','MyData');
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 件)

László Arany
László Arany 2012 年 7 月 5 日
Well, this does the trick, however, I still don't understand why my method doesn't work.

Andrei
Andrei 2012 年 8 月 13 日
編集済み: Andrei 2012 年 8 月 13 日
I have a similar problem. But I do not understand the cause

Sean de Wolski
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 ).

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by