Set Ydata in Matlab, how does it work?
Afficher commentaires plus anciens
Hello, i came across this code.
plot_handle=plot(zeros(num_samples,2));
then in another function which is called update the plot.
i saw this.
data = getdata(daq_object,num_samples);
for i = 1:length(plot_handle)
set(plot_handle(i),'YData',data(:,i));
end
I don't get how the set(plot_handle(i),'YData',data(:,i)); works, beacuse in the plot_handle function, i only have num_samples as input.
Réponse acceptée
Plus de réponses (2)
Fangjun Jiang
le 22 Juil 2011
Plot a figure:
h=plot(1:10);
type get(h) to see a list of properties. You can get the data back by:
y=get(h,'YData');
You can also change the figure by:
set(h,'YData',rand(1,10);
2 commentaires
rave
le 22 Juil 2011
Fangjun Jiang
le 22 Juil 2011
In your code, h=plot(rand(10,3),rand(10,1)) returns 3 handles indicating 3 curves. When you try to set(h), you need to provide proper data. Check out the other property such 'XData','ZData', 'CData'(for image). You'll get the idea.
Walter Roberson
le 23 Juil 2011
1 vote
When the Y value is not a vector, plot() will produce one curve for each column of Y. Your initial Y has two columns (unless numsamples is only 1), so plot() will produce two lineseries objects.
If you have more than one channel in your daq_object, then if you request to read numsamples samples, you are requesting to read that many per channel.
The rest of the code is then appropriate to update the respective plot lines according to the data received for each channel.
1 commentaire
rave
le 26 Juil 2011
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!