How can I do polynomial fitting when X-axis is time

5 ビュー (過去 30 日間)
Lee YuChang
Lee YuChang 2020 年 3 月 26 日
コメント済み: Steven Lord 2020 年 3 月 26 日
Hi ! I have a set of data that I want to do polynomial fitting, but my X-axis is duration type and the precision is up to milliseconds. I try to use seconds() to convert duration into numeric value but it ends up has many same value. And if I try to fit the curve directly it will give the following error "CLASSNAME input must be a valid numeric or logical class name". I wonder if there is any way to solve this problem
Any advise will be helpful, thanks!
data:
time value
'08:34:50.000' 20.11
'08:34:50.050' 20.12
'08:34:50.100' 20.11
'08:34:50.150' 20.00
  1 件のコメント
the cyclist
the cyclist 2020 年 3 月 26 日
It would be helpful if you uploaded your data in a mat file (using the paper clip icon), or at least a small representative sample.
What function are you using to do the fit?

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

回答 (1 件)

the cyclist
the cyclist 2020 年 3 月 26 日
Hm. Plotting the data you posted, using the seconds function, results in exactly what I would expect -- including capturing the milliseconds -- and suggests that the fit should work just fine.
time = duration(8,34,50,0:50:150)';
value = [20.11; 20.12; 20.11; 20.00];
tbl = table(time,value);
figure
plot(seconds(tbl.time),tbl.value,'.-')
  3 件のコメント
the cyclist
the cyclist 2020 年 3 月 26 日
I think you may be confusing what is stored with what is displayed. To see this, use the modulus operation to remove multiples of 60 seconds from the time. Here are the original data.
>> s1 = seconds(tbl.time);
>> mod(s1,60)
ans =
50.0000
50.0500
50.1000
50.1500
Now, convert back to duration. (You claim that the milliseconds are lost.)
d2 = duration(0,0,seconds(tbl.time));
But let's get the seconds again from the duration, and apply the modulus function again:
s2 = seconds(d2);
mod(s2,60)
ans =
50.0000
50.0500
50.1000
50.1500
The milliseconds are still there.
Steven Lord
Steven Lord 2020 年 3 月 26 日
The default display Format for duration arrays doesn't include fractional second information but you can specify a Format that does.
A = duration(0, 0, 0:0.5:2)
A.Format = 'hh:mm:ss.SS'

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by