How to overcome the data length issue in the following code?

1 view (last 30 days)
Hi,
I have 2 excel files named TimeStamps_Uy.xlsx and Head_Timestamps.xlsx. In file one: TimeStamps_Uy.xlsx column 1 have a Timestamps and column 2 have the velocity data. In file two: column 1 have a Timestamps and column 2 have the Head data. I want to use TimeStamps_Uy.xlsx file and all of its Timestamps to find the similar or the nearest Timestamps in the Head_Timestamps.xlsx hence on matching plot the corresponding data (head/Uy) hence save the timestamp, head, and Uy into new xlsx or csv file. I have tried the intern1 function so far in which I am having problem because in file Head_Timestamps.xlsx there are more data then the TimeStamps_Uy.xlsx. I am pasting the code and error below?
Code:
close all; clear all; clc;
Uy_dir = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\5-AverageFilter_VelocitiesExtration\Point_Velocities\Uy\TimeStamps_Uy.xlsx';
a = readmatrix(Uy_dir);
time_stamp_u=a(:,1);
u=a(:,2);
Head_dir = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_Head\Data_Raw\Head_Timestamps.xlsx';
a1 = readmatrix(Head_dir);
time_stamp_h=a1(:,1);
h=a1(:,2);
h_u = interp1(h,u,time_stamp_u)
Error:
Error using interp1>reshapeAndSortXandV (line 445)
X and V must be of the same length.
Error in interp1 (line 128)
[X,V,orig_size_v] = reshapeAndSortXandV(X,V);

Accepted Answer

Image Analyst
Image Analyst on 10 Mar 2022
"I have 2 excel files named TimeStamps_Uy.xlsx and Head_Timestamps.xlsx." Yes, you have them, but we don't because you forgot to attach them.
h and u are not the same lengths. What are the sizes of those arrays
size(h)
size(u)
size(time_stamp_u)
  2 Comments
Image Analyst
Image Analyst on 10 Mar 2022
See -- h and u have different lengths. You need to pass in the full x first, then the full y, then the x values that you want the interpolated values for the third argument. So the full x and y must be the full signal that you have and must be the same length since you have a y for every x.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by