Plotting In Matlab with three columns?

I want to plot the Global_X column on Y-axis and Plot_Time on X-axis for the CSV file attached. However, I am intereseted in plotting unique subplots based on vehicle ID. For example, there should be a plot(preferably represented by line) for Vehicle_ID 65 and different one for Vehicle_ID 66. This should repeat until all the plots are completed for each Vehicle_ID. I am trying to have the plots for all the vehicle_Ids on the same big plot. I would really appreciate the help.

 採用された回答

Stephen23
Stephen23 2019 年 2 月 24 日
編集済み: Stephen23 2019 年 2 月 24 日

1 投票

M = csvread('Query_version.csv',1,0);
U = unique(M(:,1));
N = numel(U);
C = cell(2,N);
for k = 1:numel(U)
X = M(:,1)==U(k);
C{1,k} = M(X,2);
C{2,k} = M(X,3);
end
plot(C{:})
Giving all 449 different lines, one for each ID:
Query.png
It is not clear how you want to distinguish between 449 different lines on one plot.

4 件のコメント

Gaurav Kashyap
Gaurav Kashyap 2019 年 2 月 24 日
Thanks a lot for the assistance. Is there a way I can have three plots? 0-300, 300-600 and above 600 being three of the ranges. The reason why I am looking at have all these plots together is study the vehicle trajectory.
Stephen23
Stephen23 2019 年 2 月 24 日
"Is there a way I can have three plots?"
Probably.
"...0-300, 300-600 and above 600 being three of the ranges."
Of which variable?
Gaurav Kashyap
Gaurav Kashyap 2019 年 2 月 24 日
The ranges are for the variable Plot_Time. This way I can look at the vehicle trajectory data on three different plots. Thanks a lot for the help.
Stephen23
Stephen23 2019 年 2 月 25 日
M = csvread('Query_version.csv',1,0);
V = [0,300,600,Inf];
[~,B] = histc(M(:,2),V);
U = unique(M(:,1));
C = cell(2,numel(U),numel(V)-1);
S = size(C);
for ii = 1:S(2)
X = M(:,1)==U(ii);
for jj = 1:S(3)
Y = B==jj;
C{1,ii,jj} = M(X&Y,2);
C{2,ii,jj} = M(X&Y,3);
end
end
subplot(3,1,1)
plot(C{:,:,1})
subplot(3,1,2)
plot(C{:,:,2})
subplot(3,1,3)
plot(C{:,:,3})
Giving (you can adjust the figure size, etc.):
Query.png

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStatics and Dynamics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by