Reputation: 4742
I wish to plot a simple graph of my data with sliders to change the coefficient of the y-axis data. I have created my GUI interface from quick start, with plot and sliders. I now wish to write the code (I believe in the simpleguide_OpeningFcn
section) to import my data sets. My data sets are 5 different 300x1
vectors which I currently import into a a normal MATLAB file using an import function named importfile2.m
.
Any help on how to get this data into the GUI for my simple plot(x,y)
would be much appreciated. Cheers
Upvotes: 0
Views: 141
Reputation: 13945
An alternative would be to use setappdata and getappdata to fetch the data wherever you want from your GUI.
For example, at t he end of your importfile2.m
you could use setappdata to store the data in some variable. The first argument tells MATLAB in what workspace to save it. You could, for example, use the GUI interface in itself or use the base workspace, accessible from everywhere. That's the most general way:
setappdata(0,'FancyName',YourData); %// The 0 is for the base workspace,i.e. the 'root'.
%//YourData is the actual data and 'FancyName' is whatever name you give them. It does not have to be the same name as the variable in your function. The important thing is to use the same name in getappdata as below.
If you wanted to associate the data only with the GUI figure, you would use something like this:
setappdata(handles.YourFigure_Tag,'FancyName',YourData);
To get the data in the GUI, use getappdata in its opening function (or in any callback you want) and you're good to go:
Data_inGUI = getappdata(0,'FancyName'):
A more robust way would be to store directly the data in the handles structure of the GUI, so that it's accessible from every callback:
handles.Data_inGUI = getappdata(0,'FancyName'):
guidata(hObject,handles); %// Update handles structure; important!
And that should do it. Hope that helps!
EDIT I think another solution would be to save a .mat
file at the end of the import function and load it in the OpeningFcn of the GUI. Than might be simpler/faster.
EDIT 2 Following your comment below, here is what I would do:
1) In the OpeningFcn of the GUI, import the data.
[Date,OutAirTemp,SupAirtemp] = importfile3('AHU7Oct.csv')
Then you can store everything in the handles structure:
handles.Data = Date;
handles.OutAirTemp = OutAirTemp;
handles.SupAirtemp = SupAirtemp;
guidata(hObject,handles); %// Update handles structure.
Then elsewhere in the GUI (i.e. other callbacks) you can fetch the data as regular, i.e. using for example:
NewDate = handles.Date - 4 %// or whatever.
Is it a bit clearer?
Upvotes: 1