Effacer les filtres
Effacer les filtres

Plot a vector with different colors on selected data

1 vue (au cours des 30 derniers jours)
Alex
Alex le 7 Août 2019
Commenté : darova le 8 Sep 2019
Hi community,
I have a vector of 700 elements. While plotting, I want to plot first 100 points in 'Red' color and the next 100 points in 'Blue' color. Later, I want to repeat them. Is there any inbuilt function to do it?
Thanks

Réponses (2)

madhan ravi
madhan ravi le 7 Août 2019
No loops needed:
v = reshape(vector,100,[]);
plot(v(:,1:2:end),'r')
hold on
plot(v(:,2:2:end),'b')
  6 commentaires
Alex
Alex le 12 Août 2019
@madhan: Any update? Thanks
darova
darova le 8 Sep 2019
Just add x data
x = linspace(0,30,700);
y = sin(x);
x1 = reshape(x,100,[]);
y1 = reshape(y,100,[]);
i1 = 1:2:size(x1,2);
i2 = 2:2:size(x1,2);
plot(x1(:,i1),y1(:,i1),'r')
hold on
plot(x1(:,i2),y1(:,i2),'b')
hold off

Connectez-vous pour commenter.


darova
darova le 12 Août 2019
SOmething like this?

Catégories

En savoir plus sur Line Plots 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