Display Graph using checkbox
4 次查看(过去 30 天)
显示 更早的评论
I have GUI with pushbutton and checkboxes, by pushbutton i am importing multiple excel files.Now i want to plot different graphs(from imported excel files) using different checkboxes,,if i click one check box it should display the graph and when uncheck graph should disappear. Please do the needful.

6 个评论
Adam
2016-4-15
Well, the code in your pushbutton keeps overwriting the same variables so the previous data gets lost.
You really shouldn't be using things like assignin and evalin in a GUI. GUI functions have their own workspace and methods for sharing data amongst those workspaces, most simply by attaching the data to the handles structure. Pinging variables into the base workspace makes it that much harder to work with them.
If you want to retain data previously loaded though you will need to use arrays to store the data and append to those arrays when you load the next data rather than overwriting them. How you do that rather depends on the exact nature of the data you are storing. If it can be of variable size then use a cell array, if the data you will load into e.g. 'a' in your code will always be the same size then you can use a numeric array with dimensionality 1 higher than the data you currently store in 'a'.
回答(1 个)
Geoff Hayes
2016-4-16
Sandy - where is your data being drawn to? Does your GUI have an axes that you are plotting the data to or are you creating a new figure for each checkbox? The latter seems to be true with your calls to figure(1) and figure(2). Why not draw both to figure(1) or add an axes to your GUI so that all data is drawn directory to that axes?
Since you wish to remove the drawn data when the checkbox is unchecked, you will need to save the graphics object handle (for each drawn object) to your handles structure so that you can then delete it. For example,
function checkbox1_Callback(hObject, eventdata, handles)
if get(handles.checkbox1,'Value')
figure(1);
aa = evalin('base','a');
bb = evalin('base','b');
handles.hCbox1Plot = plot( aa,bb,'*--','DisplayName',baseFileName);
grid on;
hold on;
guidata(hObject,handles); % do this to save the updated handles structure
else
if ~isempty(handles.hCbox1Plot)
delete(handles.hCbox1Plot);
end
end
And as Adam commented, try not to pollute the workspace with your variables. Save them to the handles structure like we did in the above with the handle to the graphics object plotted in the checkbox1_Callback.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!