Plot data vs time color coded by ID
Mostrar comentarios más antiguos
Hi,
MATLAB newbie here. I'm trying to plot the range in miles of two aircraft from where I am over time on the same plot.
Here is an example of the data from a table named 'data':
'15:02:03' 1 24.492
'15:02:03' 2 25.653
'15:02:04' 1 24.489
'15:02:04' 2 25.650
'15:02:05' 1 24.485
'15:02:05' 2 25.646
'15:02:06' 1 24.482
'15:02:06' 2 25.643
'15:02:07' 1 24.478
'15:02:07' 2 25.639
---------------------------
The variables I'm using are:
Column 1 is data.time
Column 2 is data.ID
Column 3 data.range
I'm able to plot time vs. range using plot(data.time, data.range), but what I need to do is plot each aircraft's range vs. time color coded by data.ID and I thought it would be simpler than it is, but I'm a stumped. I'm pretty sure I need a for loop to loop through data.ID in data but can't figure out the syntax. Thanks for any help!
JB
2 comentarios
Image Analyst
el 12 de Feb. de 2022
Is data.time string or character variables? Or time series variable? Or doubles? It's easiest if they're numerical not strings. Please attach your table in a .mat file with the paperclip icon so we can begin on helping you.
save('answers.mat', 'data')
Jen B
el 12 de Feb. de 2022
Respuesta aceptada
Más respuestas (1)
time = ['15:02:03'; '15:02:03'; '15:02:04'; '15:02:04'; '15:02:05'; '15:02:05'; '15:02:06'; '15:02:06'; '15:02:07'; '15:02:07'];
ID = [1 2 1 2 1 2 1 2 1 2]';
range = [24.492 25.653 24.489 25.65 24.485 25.646 24.482 25.643 24.478 25.639]';
data = table(time,ID,range);
% convert times to duration
data.time = duration(string(data.time),"InputFormat","hh:mm:ss")
gscatter(data.time, data.range,data.ID)
idData = unstack(data,"range","ID")
plot(idData.time,idData{:,["x1","x2"]})
legend
1 comentario
Jen B
el 12 de Feb. de 2022
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


