Random values in timetable

4 ビュー (過去 30 日間)
Robin Karl
Robin Karl 2021 年 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 件のコメント
Wan Ji
Wan Ji 2021 年 8 月 24 日
>> data
data =
5×1 timetable
Time Conductivity
___________________ _________________
2021-08-24 19:56:43 0.179120082915553
2021-08-24 19:56:43 0.680274695194285
2021-08-24 19:56:43 0.915462391603304
2021-08-24 19:56:43 0.12286950797456
2021-08-24 19:56:43 0.585484044951836
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)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by