Random values in timetable

1 次查看(过去 30 天)
Robin Karl
Robin Karl2021-8-24
编辑: Turlough Hughes ,2021-8-24
Hello, first of all I'm quite a Matlab newbie.
My goal is to fill a time table with random values.
Currently, the current value of the loop keeps overwriting the previous value. However, I would like to have all values in one timetable.
n=1
for i = 1:5
Time = datetime('now');
Conductivity = rand(1,1);
pause(n);
data = timetable(Time,Conductivity);
end
Thanks in advance for your help!

采纳的回答

Wan Ji
Wan Ji 2021-8-24
Do by the following code
data = timetable;
n=1;
for i = 1:5
Time = datetime('now');
Conductivity = rand(1,1);
pause(n);
data = [data;timetable(Time,Conductivity)];
end
  2 个评论
Robin Karl
Robin Karl 2021-8-24
Thanks ! That was fast :) works perfect

请先登录,再进行评论。

更多回答(1 个)

Turlough Hughes
Turlough Hughes 2021-8-24
编辑:Turlough Hughes 2021-8-24
You can collect the data in the loop and then use timetable
n = 1;
for i = 1:5
Time(i,1) = datetime('now');
Conductivity(i,1) = rand();
pause(n)
end
data = timetable(Conductivity,'RowTimes',Time)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by