Countering error while using interp1 function
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Walter Roberson
2022년 3월 13일
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
muhammad choudhry
2022년 3월 13일
Walter Roberson
2022년 3월 13일
편집: Walter Roberson
2022년 3월 13일
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
2022년 3월 13일
Peter Perkins
2022년 3월 14일
I don't think these are datetimes, I think they are durations.
muhammad choudhry
2022년 3월 14일
Peter Perkins
2022년 3월 14일
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.
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!