Re-plotting of data on same GUI axes in matlab

조회 수: 4 (최근 30일)
Observer
Observer 2015년 6월 9일
편집: Adam 2015년 6월 9일
I am working with GUI in matlab and I have one axes to plot the data. I want to keep track what I have already plotted in order to re-plot it if needed on same axes and for this purpose, I have list box which holds names of data sets which I have plotted. I am trying to find appropriate way to select the name of data set in list box and re-plot the data set on axes. I am setting some properties of axes while plotting, so I do not not want to perform the re-plotting operation, instead, I want re-use the handle (of some kind) to get the plot data again.
I have some experience of using figure handle to get figure by providing its handle but I am looking something similar for plotting in axes.
f1 = figure
plot ([0:0.1:2*pi] , cos ([0:0.1:2*pi]))
f2 = figure
plot ([0:0.1:2*pi] , sin([0:0.1:2*pi]))
figure(f1) or figure (f2)

답변 (1개)

Adam
Adam 2015년 6월 9일
편집: Adam 2015년 6월 9일
hPlot = plot( hAxes, [0:0.1:2*pi] , cos ([0:0.1:2*pi] );
will plot on the axes specified by hAxes (which can be acquired easily whether you are using GUIDE or just creating the axes as you go) and return the handle to the Line object of the plot in hPlot.
You can then use, e.g
set( hPlot, 'XData', 0:0.1:4*pi, 'YData', cos ([0:0.1:4*pi]) )
That is just a quick example. Personally I would factor the common 0:0.1:4*pi out into a variable, but I was following your example here!
I'm not sure what happens if you just do:
hPlot.XData = 0:0.1:4*pi;
in this case. You have to be careful when changing a property which effects others too as in a line plot it is expected that XData and YData are the same length so changing just one to a different length presumably results in a bug. I haven't tried it.
I'm not 100% clear exactly what your question was though since you talk about list boxes too, but don't appear to be asking about those.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by