Plot data vs time color coded by ID
이전 댓글 표시
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
Image Analyst
2022년 2월 12일
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
2022년 2월 12일
채택된 답변
추가 답변 (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
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


