- I don't understand why they need [x;x] instead of just x, y and z, but removing the additional x the trick fails. Does anyone have some ideas on solving this problem?
How to interpolate color along a curve with specific colors?
30 visualizaciones (últimos 30 días)
xiaojuezi el 11 de Abr. de 2020
Hi, I have a curve of dimension 50x2, and a specification of the colors at certain positions. For example, at position 1 the color is [1,0,0] and at position 30, the color is [0,1,0] and at position 50 the color is [0,0,1]. I would like to plot this curve such that, at positions 1, 30 and 50, they have the specified colors, while at other positions, the colors are interpolated. And optimally I would like to have continuous plot rather than dividing the curve into segments.
I read from this trick that you can plot it as a surface with no face color, but I have no idea how would you specify the colors with this method. In th trick they have:
x = 0:.05:2*pi;
y = sin(x);
z = zeros(size(x));
col = x; % This is the color, vary with x in this case.
I don't understand why they need [x;x] instead of just x, y and z, but removing the additional x the trick fails. Does anyone have some ideas on solving this problem?
Thank you very much!
darova el 11 de Abr. de 2020
Try this trick
Because it's actualy a surface. And surface wants it's inputs to be always of 2x2 size minimum
Here is another way to plot color line
x = 0:10;
y = sin(x);
c = jet(length(x)+1); % can be array of size Nx3 or Nx1
patch('xdata',[x nan],... % add NaN to prevent MATLAB to draw faces
'edgecolor','flat') % or 'interp'