How can I plot a table with data and time ?

5 views (last 30 days)
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

Accepted Answer

Cris LaPierre
Cris LaPierre on 30 Mar 2021
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"]})

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!