How can I plot a curve while changing color every N points ?

조회 수: 1(최근 30일)
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
for j=1:NdC % NdC is an input which refers to the number of cycles in the experiment, what I called N just before
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 !!

채택된 답변

Jon 2022년 7월 26일
편집: Jon 2022년 7월 26일
I was coding up the example below, and by the time I posted I saw you already had an answer from @Cris LaPierre. I will still include mine in case it provides you with any further ideas. I had understood that you wanted a seperate curve for each cycle, each with a different color, rather than just one curve with the colors changing as @Cris LaPierre shows.
% make some example data
numCurves = 30;
x = linspace(0,100,50)';
Y = x*linspace(0,25,numCurves);
% make color map
colors = jet(numCurves); % could use others, e.g csv, winter etc
% plot curves
hold on
for k = 1:numCurves

추가 답변(1개)

Cris LaPierre
Cris LaPierre 2022년 7월 26일
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
ind = 0:162:length(L); % indices of bounding each group
for j=2:length(ind)
hold on
hold off




Community Treasure Hunt

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

Start Hunting!

Translated by