Display Graph using checkbox
Mostrar comentarios más antiguos
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 comentarios
Jan
el 31 de Mzo. de 2016
This is a very vague question. What have you tried so far and which problems occur? How could be suggest a matching code based on the screenshot of the GUI only?
Sandy Baha
el 15 de Abr. de 2016
Editada: Sandy Baha
el 15 de Abr. de 2016
Adam
el 15 de Abr. de 2016
You need to define clearly what the expected behaviour is based on user actions. Technical problems like this regularly arise from simply not having considered exactly what is supposed to be the behaviour when buttons or checkboxes are clicked in various orders.
I'm still not clear what the order of user actions is here and what the expected responses are. You say it doesn't work for multiple files. So I assume every time the user clicks the button all the previous loaded data is expected to remain?
Sandy Baha
el 15 de Abr. de 2016
Editada: Sandy Baha
el 15 de Abr. de 2016
Adam
el 15 de Abr. de 2016
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'.
Sandy Baha
el 15 de Abr. de 2016
Respuestas (1)
Geoff Hayes
el 16 de Abr. de 2016
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.
1 comentario
Sandy Baha
el 18 de Abr. de 2016
Categorías
Más información sobre Environment and Settings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!