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

4 visualizzazioni (ultimi 30 giorni)
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 Commento
the cyclist
the cyclist il 26 Mar 2020
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?

Accedi per commentare.

Risposte (1)

the cyclist
the cyclist il 26 Mar 2020
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 Commenti
the cyclist
the cyclist il 26 Mar 2020
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 il 26 Mar 2020
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'

Accedi per commentare.

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by