How to update Subplots in GUI

11 Ansichten (letzte 30 Tage)
Hiranth Shenal Fernando
Hiranth Shenal Fernando am 14 Dez. 2018
Kommentiert: Adam Danz am 19 Dez. 2018
Hi there,
I'm having trouble in generating a subplot for my GUI.
I essentially have a gui linked to a chickbox that creates a subplot based on which checkboxes are selected. However, I need to also rewrite what's in my GUI axis after each plot; this means that every time I plot my data, I need the axes in Guide I created to update as well. Before data was being plotted on the same types of plots meaning that (for example) height and weight were both the y axis and while I graphed height first then tried to plot weight, weight ended up using the same subplot configuration as the height plot and both were displayed as well.

Antworten (1)

Adam Danz
Adam Danz am 14 Dez. 2018
Bearbeitet: Adam Danz am 14 Dez. 2018
Presumably your axes are created from within the GUI. Are you using GUIDE or are you building the GUI from scratch? In any case, when you create the axes, you need to store the axis handles. If you're using GUIDE, they are already stored in the list of handles. If you're building the GUI from scratch, you need to store the axis handles when you great the axes. For each checkbox callback function, you need to specify which axis it should alter. I can't really be more specific without knowing how you've created the GUI. If needed, I can add more detail in the comments below if you need more help with my solution.
  2 Kommentare
Hiranth Shenal Fernando
Hiranth Shenal Fernando am 19 Dez. 2018
Like I said above, I built with GUIDE.
I fixed my issue with changing graphs somehow but now I can't seem to clear multiple graphs.
For instance if I chose an option to display two graphs, but then wanted to only show one.
I've used clf but it only clears the axes for the second graph despite choosing the axes object I placed in the GUI. I'm using if statements to callback to my checkboxes to see if they are ticked but the switching of graphs still isn't 100% in doing the same data. What I mean is that I have multiple types of graphs and switching between them makes a new plot without displaying the new data on old axes. An entirely new plot is formed. But when choosing graphs within one set of data, I can't seem to clear for different subplot amounts.
(sorry thought I put under comment)
Adam Danz
Adam Danz am 19 Dez. 2018
"I fixed my issue with changing graphs somehow..."
If you're unsure why your code works now you might want to invest some time understanding what was wrong and how you fixed it. You might find that the solution isnt' general or causes a different set of problems.
"I've used clf but it only clears the axes for the second graph despite choosing the axes object I placed in the GUI"
The clf command clears a figure, cla clears an axis. If you want to clear a specific axis you need to include the handle: cla(h) where h is the handle to the axis you want to clear.
It sounds like all of your problems can be solved by using axis handles as I mentioned in my solution.
For example:
figure;
axh = axes; %axh is the handle to my axes
plot(axh, rand(1,20))
%clear axes
cla(axh)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by