How to plot a trajectory with varying colour?
Afficher commentaires plus anciens
I'm trying to plot the trajectory which also shows error characteristics visually.

Inputs: East(m), North(m), error(m)
error = sqrt((East_radar - North_GPS)^2 + (East_GPS - North_GPS)^2)
At present, I'm able to plot trajectory, with the marker indices representing the points where the error is high. I have implemented the code as seen below.
To make this visualization better, how can I represent the trajectory with varying colour representing error value? as shown below.
So, higherror represents Red and low error represents Green? Your assistance would relly help me.Thanks!
If my query is unclear, please revert.

figure()
plot(Radar_East, Radar_North,'LineStyle','-')
xlabel('East (m)')
ylabel('North (m)')
title('GPS EN plot')
hold on
plot(Radar_East(outliers),Radar_North(outliers),'o','MarkerSize',8);
legend('RADAR Trajectory','Outliers > 99 percentile')
hold off
Réponse acceptée
Plus de réponses (2)
I don't think there is a way to do this using just one plot. My quick solution would be to do something like this
x = 0:0.05:2*pi; %sample x data
y = sin(x); %sample y data
c = hsv(length(x)); %hsv values over the length of x
hold on %hold the graph
for ii = 1:length(x)-1
plot(x(ii:ii+1),y(ii:ii+1),'-','Color',c(ii,:)) %plot
end
hold off
Not the most elegant solution, but if really want to do it, this is a way. One problem with this approach would be if you have few data points. You could spline or smooth your data though.
3 commentaires
John D'Errico
le 23 Fév 2023
Modifié(e) : John D'Errico
le 23 Fév 2023
My gut said oh, sure. This must be possible, probably using line. Line should accept a color spec at each point along the line. It just makes sense this is where I would find it, with one of the possibiities for the 'color' property would be the colors to use. Then I checked. Time for a feature request. :)
Maheedhar Korimi
le 23 Fév 2023
Maheedhar Korimi
le 23 Fév 2023
Les Beckham
le 23 Fév 2023
0 votes
Take a look at this Answer which shows a trick for doing this using surface.
5 commentaires
Maheedhar Korimi
le 23 Fév 2023
Les Beckham
le 23 Fév 2023
If you provide more details (your data and the code you are using to plot it, and the exact errors or undesired behavior you are seeing) someone can probably help work out the issues you are having.
Maheedhar Korimi
le 24 Fév 2023
Modifié(e) : Maheedhar Korimi
le 24 Fév 2023
Les Beckham
le 24 Fév 2023
"provide more details (your data and the code you are using to plot it".
Are we supposed to guess what you are trying to plot (and how)?
Maheedhar Korimi
le 24 Fév 2023
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


