Retrieveing and replacing data in a plot

34 views (last 30 days)
Hi Everyone,
I've created a GUI which plots multiple sets of data [x column of data is constant whilst there are multiple y columns of data]. Once the figure is open, a button appears which allows the user to filter the data [using butter and filtfilt]. As I've programmed it to filter again by a certain factor with every click, it's important that the process can occur more than once.
As this is part of a very complicated GUI, I don't want to overwrite the original plot by using another plot() function. What I would ideally like to do is after I have retrieved the data using
YData = get(gcf,'YData')
and changed it, I'd like to replace it by saying
set(gcf,'YData',YData)
This works fine when I have only one set of YData on the graph, but is there a way I can implement this with multiple vectors? Every time I attempt this I recieve the anticipated error that it cannot plot from cell array as there are multiple columns of y-axis data.
Thanks,
Rosie

Accepted Answer

Matt Fig
Matt Fig on 10 Aug 2012
I'm a little confused. There is no ydata property for figures. Did you mask the GCF function with the line object's handles?
Any way, try this:
% First plot the data:
x = 1:10;
L = plot(x,x.^2,x,x.^2.2); % Return handles to lines.
pause; % Look at the plot, the press return...
ydata = get(L,'ydata');
ydata{1} = sqrt(ydata{1}); % Alter the first cell.
set(L,{'ydata'},ydata) % Reset the data.
  1 Comment
Rosie
Rosie on 14 Aug 2012
Thanks so much, Matt.
Turns out the only thing missing were the curly brackets around 'YData' - amateur mistake =\
Thanks again

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 10 Aug 2012
maby you should convert your data from cell to mat
ydata=cell2mat(ydata)
  1 Comment
Rosie
Rosie on 13 Aug 2012
Thanks for the quick response.
I tried this before. Unfortunately it seems to want only a single vector of ydata. What bothers me is that I recieved it in 2 cells of data, so why can't I put it back in the form of 2 cells of data?
Or is there some way I can trick it into putting it back?

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!