Animating plot with GUI

14 views (last 30 days)
Ethan
Ethan on 25 Jun 2011
I built a script that animated a data file by:
1. linking XDataSource and YDataSource to x and y, respectively
2. changing x and y
3. using "refreshdata" to update the plot
Worked great.
Now I'm trying to build a GUI that does this at the push of a button, but YDataSource doesn't seem to exist in the axes. My code is essentially:
x1 = 1000;
x2 = x1 - handles.window;
x = x2:x1;
y = handles.rawD(x,1);
plot(handles.data,x,y);
set(handles.data,'YDataSource','y')
set(handles.data,'XDataSource','x')
And I get the error:
??? Error using ==> set
There is no 'YDataSource' property in the 'axes' class.
When I go to the data axes properties window in the GUIDE editor, there is no YDataSource property. What's the other option?
Thanks in advance! -Ethan

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jun 2011
h = plot(handles.data,x,y);
set(h,'YDataSource','y')
set(h,'XDataSource','x')
Note: this will only work if your x and y values are vectors. In particular if your y is not a vector, then plot() will output multiple lineseries handles, and each of them needs a different YDataSource.
Note that the variables you specified ('x' and 'y') must exist in the Base Workspace for refreshdata() to be able to find them, unless you use the 'workspace' option; see http://www.mathworks.com/help/techdoc/ref/refreshdata.html
  1 Comment
Ethan
Ethan on 27 Jun 2011
Ah! Perfect! Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!