YDataSource problems

18 visualizzazioni (ultimi 30 giorni)
Ethan
Ethan il 9 Lug 2011
Hi there,
I'm trying to create an animated plot with data from four sensors. I got it to work with the data from one sensor using the refreshdata command. However, refreshdata didn't like plotting more than one column of data. I was hoping that the following code would work, but I get the error:
??? Error using ==> set Invalid handle object.
Error in ==> guiTest>pushbutton_Play_Callback at 450 set(h1,'YDataSource','handles.y1')
What am I doing wrong... and maybe more to the point... what's the best way to plot multiple lines in the same graph and then update it many times/sec?
A snippet of code is below. Thanks!
handles.y1 = rawData(handles.x,1);
handles.y2 = rawData(handles.x,2);
handles.y3 = rawData(handles.x,3);
handles.y4 = rawData(handles.x,4);
h1 = plot(handles.data,handles.x,handles.y1);
h2 = plot(handles.data,handles.x,handles.y2);
h3 = plot(handles.data,handles.x,handles.y3);
h4 = plot(handles.data,handles.x,handles.y4);
set(h1,'YDataSource','handles.y1')
set(h1,'XDataSource','handles.x')
set(h2,'YDataSource','handles.y2')
set(h2,'XDataSource','handles.x')
set(h3,'YDataSource','handles.y3')
set(h3,'XDataSource','handles.x')
set(h4,'YDataSource','handles.y4')
set(h4,'XDataSource','handles.x')

Risposte (1)

Paulo Silva
Paulo Silva il 9 Lug 2011
Use lines instead of plots and change their xdata and ydata everytime you want to update them.
I can't understand that code, you are changing the datasource for what purpose?
  1 Commento
Ethan
Ethan il 9 Lug 2011
After the code I posted above, I have a while loop that goes through and changes the "window."
My while loop is increasing the value of 'k', and handles.x = k:k-window
Then I update handles.x and handles.y1 through handles.y4 and refreshdata.
This works fine:
handles.y = rawData(handles.x,1);
h = plot(handles.data,handles.x,handles.y);
set(h,'YDataSource','handles.y')
set(h,'XDataSource','handles.x')
while (k < (theEnd + 1))
handles.x1 = k
handles.x2 = handles.x1 - window;
handles.x = handles.x2:handles.x1;
handles.y = rawD(handles.x,1);
refreshdata(handles.data,'caller')
k = k+1;
end
I WISH this worked, but it doesn't:
handles.y = rawData(handles.x,1:4);
h = plot(handles.data,handles.x,handles.y);
set(h,'YDataSource','handles.y')
set(h,'XDataSource','handles.x')
while (k < (theEnd + 1))
handles.x1 = k
handles.x2 = handles.x1 - window;
handles.x = handles.x2:handles.x1;
handles.y = rawD(handles.x,1:4);
refreshdata(handles.data,'caller')
k = k+1;
end
This is what I'm currently trying to do, but it doesn't work either:
handles.y1 = rawData(handles.x,1);
handles.y2 = rawData(handles.x,2);
handles.y3 = rawData(handles.x,3);
handles.y4 = rawData(handles.x,4);
h1 = plot(handles.data,handles.x,handles.y1);
h2 = plot(handles.data,handles.x,handles.y2);
h3 = plot(handles.data,handles.x,handles.y3);
h4 = plot(handles.data,handles.x,handles.y4);
set(h1,'YDataSource','handles.y1')
set(h1,'XDataSource','handles.x')
set(h2,'YDataSource','handles.y2')
set(h2,'XDataSource','handles.x')
set(h3,'YDataSource','handles.y3')
set(h3,'XDataSource','handles.x')
set(h4,'YDataSource','handles.y4')
set(h4,'XDataSource','handles.x')
while (k < (theEnd + 1))
handles.x1 = k
handles.x2 = handles.x1 - window;
handles.x = handles.x2:handles.x1;
handles.y1 = rawDImport(handles.x,1);
handles.y2 = rawDImport(handles.x,2);
handles.y3 = rawDImport(handles.x,3);
handles.y4 = rawDImport(handles.x,4);
refreshdata(handles.data,'caller')
k = k+1;
end

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by