필터 지우기
필터 지우기

Retrieveing and replacing data in a plot

조회 수: 40 (최근 30일)
Rosie
Rosie 2012년 8월 10일
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

채택된 답변

Matt Fig
Matt Fig 2012년 8월 10일
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
Rosie
Rosie 2012년 8월 14일
Thanks so much, Matt.
Turns out the only thing missing were the curly brackets around 'YData' - amateur mistake =\
Thanks again

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 10일
maby you should convert your data from cell to mat
ydata=cell2mat(ydata)
  댓글 수: 1
Rosie
Rosie 2012년 8월 13일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by