Effacer les filtres
Effacer les filtres

I am plotting the moving median of the result of a for loop, but it is plotting multiple lines?

1 vue (au cours des 30 derniers jours)
My code goes something like this
hold on
For i = 1:end;
result(i)= calc;
median = movmedian(result,10);
plot(i,median);
end
As the median is calculated, multiple lines are being plotted, proportional to the moving median range I'm using... any ideas?

Réponse acceptée

Mark Lepage
Mark Lepage le 27 Juin 2017
Figured it out,
Just needed to plot the value of median i.e.
plot(i,median(i),'or')

Plus de réponses (1)

Geoff Hayes
Geoff Hayes le 27 Juin 2017
Mark - you have hold on which will retain the current plot when adding new ones. And since you call plot on each iteration of your for loop, then you will see all lines. If you wish to only show the latest value, then you can either remove the hold on or you can change the x and y data for the first drawn plot graphics object. For example,
figure;
ylim([0 255]);
xlim([1 5]);
hold on;
hPlot = plot(NaN,NaN);
for i = 1:5
set(hPlot, 'XData',i, 'YData', randi(255,1,1), 'LineStyle', 'o');
pause(1.0);
end
So we create one plot graphics object and use it's handle to change/set the x and y data on each iteration of the loop
Note that your for loop iterates from 1:end. Is this intentional or a typo?

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by