Plot time series data colored by color coded by ID

11 ビュー (過去 30 日間)
Jennifer
Jennifer 2021 年 4 月 9 日
コメント済み: Jennifer 2021 年 4 月 10 日
Hi,
I'm trying to plot a set of data (example: aircraft data) from a .csv file from three columns:
Aircraft ID, Time, and Altitude
I would like to plot altitude over time and then be able to color code each line by the aircraft ID. I know I need a for loop and I also need to specify colors in the loop but I'm not sure how to get started. Thank you!

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 9 日
t = readtable('YourFile.csv');
[G, ID] = findgroups(t{:,1});
hold on
h = splitapply(@plot, t{:,2}, t{:,3}, G);
xlim auto; ylim auto
if isnumeric(ID)
legend(string(ID));
else
legend(ID);
end
h will now be a vector of chart line objects. Different color and line style combinations will have automatically been chosen for the lines, but at this point you can also set the line() properties as desired. For example,
color_cell = num2cell( parula(size(ID,1)), 2);
set(h, {'Color'}, color_cell); %important that you use cell array for property name
  1 件のコメント
Jennifer
Jennifer 2021 年 4 月 10 日
Wow, that was quick! I'll give it a try. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGuidance, Navigation, and Control (GNC) についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by