Shifting plotted points from green to red
Show older comments
Hi, I'm not sure how to go about this, but I'm currently trying to create a figure in which x and y position are plotted from a 2177x30 table. I want to make it so the first point is green and the last point is red. I'm trying to shift the points from green to red as they near the end of the plot so you can clearly follow the position as time goes by. For example say your plotting 100 points, then point 1 would be green, point 51 would be yellow, and point 100 would be red. Is there a way to do that? Currently I have this matlab code below as well as attatched my current output:
clc; clear;
data_HAND = readtable ('JARED_HAND.xlsx');
figure
plot(data_HAND.HAND1X,data_HAND.HAND1Y)
hold on
plot(data_HAND.HAND2X,data_HAND.HAND2Y)
hold on
plot(data_HAND.HAND3X,data_HAND.HAND3Y)
hold on
plot(data_HAND.HAND4X,data_HAND.HAND4Y)
hold on
plot(data_HAND.HAND5X,data_HAND.HAND5Y)
hold on
plot(data_HAND.HAND6X,data_HAND.HAND6Y)
hold on
plot(data_HAND.HAND7X,data_HAND.HAND7Y)
hold on
plot(data_HAND.HAND8X,data_HAND.HAND8Y)
hold on
plot(data_HAND.HAND9X,data_HAND.HAND9Y)
hold on
plot(data_HAND.HAND10X,data_HAND.HAND10Y)
hold on
plot(data_HAND.HAND11X,data_HAND.HAND11Y)
hold on
plot(data_HAND.HAND12X,data_HAND.HAND12Y)
hold on
plot(data_HAND.HAND13X,data_HAND.HAND13Y)
hold on
plot(data_HAND.HAND14X,data_HAND.HAND14Y)
hold on
plot(data_HAND.HAND15X,data_HAND.HAND15Y)
title('Hand')
xlabel('x position (mm)')
ylabel('y position (mm)')
Accepted Answer
More Answers (1)
@Jared Dube, to plot a line with continuously variable color:
t=0:100;
x=-500*cos(2*pi*t/100);
y=500*(x/500).^2+t;
hsv=[linspace(.333,0,length(x))',ones(length(x),1),linspace(.5,1,length(x))'];
cmap=hsv2rgb(hsv); % array of colors
surface([x;x],[y;y],zeros(2,length(t)),[t;t],...
'facecol','no','edgecol','interp','linew',2);
colormap(cmap); % use cmap and t values to color the line
c=colorbar; % display colorbar (optional)
c.Label.String = 'Time (s)'; % add label
xlabel('X (mm)'); ylabel('Y (mm)'); grid on
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

