Countering error while using interp1 function
Show older comments
Hi,
I am using the code below but getting the error and can not make sense of that error can anyone help please: Attached are the files I am working with.Basically, I am trying to use the time stamps available in both files attached and find the common timestamps for both velocity and head data hence plot them for visualization but I think the size of the both files are different that's why error occuring?
Code:
close all; clear all; clc;
% read data into tables
Udat = readtable('F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\5-AverageFilter_VelocitiesExtration\Point_Velocities\Uy\TimeStamps_Uy.xlsx');
Hdat = readtable('F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_Head\Data_Raw\Head_Timestamps.xlsx');
% assign variables
tu = datetime(Udat.TimeStamp); % convert to datetime array
u = Udat.Uy
th = datetime(Hdat.TimeStamp);% convert to datetime array
h = Hdat.Head_mm_; % Matlab converts original heading Head(mm) to this legal variable name
% interpolate values for head at times to match those where we have
% velocity data
hq = interp1(th,h,tu);
% plot the results
plot(u,hq,'-o')
Error:
Error using datetime (line 597)
Numeric input data must be a matrix with three or six columns, or else three, six, or seven separate numeric arrays. You can also create datetimes from a
single numeric array using the 'ConvertFrom' parameter.
Error in headvelocitygraph (line 10)
th = datetime(Hdat.TimeStamp);% convert to datetime array
Accepted Answer
More Answers (1)
Walter Roberson
on 13 Mar 2022
th = datetime(Hdat.TimeStamp);% convert to datetime array
You did not use any options when you readtable(): how can you be sure that TimeStamp was read in as either string array or cell array of character vectors? How do you know that the format was not recognized and it might already have been converted to datetime? Or perhaps the column got misidentified as numeric?
7 Comments
muhammad choudhry
on 13 Mar 2022
Walter Roberson
on 13 Mar 2022
Edited: Walter Roberson
on 13 Mar 2022
The field might be a numeric field that is storing data in terms of full days. 13 hours is about 0.56 days. The mini-viewer on my phone says that there is no date in the field.
muhammad choudhry
on 13 Mar 2022
Peter Perkins
on 14 Mar 2022
I don't think these are datetimes, I think they are durations.
muhammad choudhry
on 14 Mar 2022
Peter Perkins
on 14 Mar 2022
I can't answer that. You need to have at least some idea what is in your data files. datetime assumes that if you give it a partial (time-only) timestamp, you mean "today". In my opinion, your data files are the culprit and are not formatted properly.
Categories
Find more on Data Type Conversion 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!