How can I plot a table with data and time ?

조회 수: 4 (최근 30일)
Coginator
Coginator 2021년 3월 30일
답변: Cris LaPierre 2021년 3월 30일
Hi
I have a Problem. I have a 94x4 table with one time array and thre arrays with data.
the time array has the formation
00:14:49
00:29:49
00:44:49
....
for example
the data are
0.104
0.106
0.111
...
Im using this script:
data = readtable("xxx.csv");
plot(data.time,data.A1,data.A2,data.A3);
hold on
grid on
plot(data.time,data.A1,data.A2,data.A3);
xlabel("Zeit"),ylabel("Trübung")
legend('A1', 'A2','A3','location','best')
How can i convert the data form time in a formation that works?
Sorry for my bad englisch... hope someone can help me

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 30일
What data type are you using to store your times? If you make it a duration, it will work.
time = ["00:14:49"; "00:29:49"; "00:44:49"];
A1 = rand(3,1);
A2 = rand(3,1);
A3 = rand(3,1);
data = table(time,A1,A2,A3)
data = 3×4 table
time A1 A2 A3 __________ ________ _______ ________ "00:14:49" 0.54936 0.65717 0.034715 "00:29:49" 0.038974 0.79033 0.57317 "00:44:49" 0.86261 0.0525 0.067554
% Converte time to duration
data.time = duration(data.time,'InputFormat','hh:mm:ss')
data = 3×4 table
time A1 A2 A3 ________ ________ _______ ________ 00:14:49 0.54936 0.65717 0.034715 00:29:49 0.038974 0.79033 0.57317 00:44:49 0.86261 0.0525 0.067554
Note that your plot syntax will create 2 lines
  1. (data.time, data.A1) and
  2. (data.A2, data.A3)
You also repeat the plot command twice. You only need in once.
I assume you want 3 lines, all with time as the x value. In that case, try the following (assuming time is now a duration).
plot(data.time,data{:,["A1","A2","A3"]})

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by