How can I save data in a GUI?

5 次查看(过去 30 天)
Hi all! I'm implementing a GUI with GUIDE but I have some troubles. The first problem is to load data from the workspace. Data is a struct. This is the code I've writenn:
EEGHere = evalin('base','EEG'); DataHere = EEGHere.data;
is it right? Can I use the DataHere inside GUI function?
The second problem is that I want to save in a row vector, a row from matrix DataHere. The row vector to save, is the return of an edit in GUI (users write a number that correspond to a row of matrix). I've tried to write this command:
channel = get(handles.editchannel); signal = DataHere(channel,:);
but displays this error ??? Error using ==> subsindex Function 'subsindex' is not defined for values of class 'struct'.
How can I do?

采纳的回答

Kevin Claytor
Kevin Claytor 2012-7-19
A couple of things. You seem to be on the right track with your data loading;
EEGHere = evalin('base','EEG'); DataHere = EEGHere.data;
But you may want to store it in handles;
handles.DataHere = DataHere; guidata(hObject, handles); % Update handles
because the GUI is comprised of a bunch of different functions (callbacks, user-defined functions, etc.), and DataHere is only available to the function in which it is defined (unless you explicitly pass it to another function). On the other hand, handles is stored in the GUI figure, and all the callbacks usually have access to it. You just have to make sure to keep it up-to-date with the guidata command. That is, if you change the value of handles.DataHere in a subfunction, and want to keep that value changed in the function that called it, you'll have to run guidata(...) within the subfunction.
Now this command;
channel = get(handles.editchannel); signal = DataHere(channel,:);
is about halfway there, get(handles.editchannel), returns a structure with all the properties from editchannel. I think you want a specific property, maybe;
channel = get(handles.editchannel,'Value');
Now if editchanel is an editbox, this will return a string not a number, so you'll have to use str2num() on the output as well.

更多回答(1 个)

Fa'
Fa' 2012-7-19
Thank you Kevin. Code it's ok now. I've a last question: I want to see if data charged in row vector "signal" is the correct one. There's a possibility to see it in the workspace? Thank you very much for your attention.

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by