How can I save data in a GUI?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Kevin Claytor
le 19 Juil 2012
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.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!