How to overcome the data length issue in the following code?
조회 수: 2 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
채택된 답변
Image Analyst
2022년 3월 10일
"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
Image Analyst
2022년 3월 10일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!