How can I plot a curve while changing color every N points ?
Afficher commentaires plus anciens
Hello !
I am working on a code to plot my datas. Thoses datas are measurements of N cycles, each have 162 points. The thing is that my ouput is one .txt file of N*162 lines. I can plot those but I am struggling to find how I can associate a different color every 162 points (and in my dreams those colors are also a gradient so we can see the evolution clearly). I tried to do it as a for loop :
C=() %Here I should put something to sweep a gradient color range but I have nonn clue what can I put
L=linspace(-40,40,PpC/2); %PpC is an input which refers to the number of points per cycle, so 162
figure
for j=1:NdC % NdC is an input which refers to the number of cycles in the experiment, what I called N just before
plot(L,mapcomplete,'color',C(j))
end
Obvisouly this doesn't work but I just would like to give you the path I am working on.
Also I link an example of .txt file I use if it might help.
Thank you a lot !!
I.
Réponse acceptée
Plus de réponses (1)
You would have to have a separate plot call for each line segment. Maybe something like this?
N = 10;
C=parula(N); % returns 256 colors from the parula colormap
L=linspace(-40,40,N*162);
Y=rand(size(L));
ind = 0:162:length(L); % indices of bounding each group
for j=2:length(ind)
plot(L(ind(j-1)+1:ind(j)),Y(ind(j-1)+1:ind(j)),"Color",C(j-1,:))
hold on
end
hold off
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

