My interpolation works for one set, but does not work for the other

조회 수: 7 (최근 30일)
Ismail Qeshta
Ismail Qeshta 2017년 11월 12일
댓글: Ismail Qeshta 2017년 11월 12일
Hi,
I am using the following code for interpolation from data in files. The problem is that the code runs very nicely in the first set, X1, Y1, while it shows that the X and V values don't have the same length in the second set: X2, Y2. I can't figure out the problem. Both codes present the same type of results and have same column length. The files of both sets are attached herewith.
clear; clc;
y=load ('Y1.txt');
x=load ('X1.txt');
plot(x(:,2),-sum(y(:,2:11),2))
y1=-sum(y(:,2:11),2);
x1=x(:,2);
y3=unique(y1);
x3=unique(x1);
y2 = [1308.9, 2514.9, 4797.9]*1000;
x2 = interp1(y3, x3, y2, 'linear');
figure(1)
plot(x1, y1, '-g')
hold on
plot(x2, y2, 'bp')
hold off
grid
legend('Data', 'Interpolated Points', 'Location', 'NW')
  댓글 수: 1
Ismail Qeshta
Ismail Qeshta 2017년 11월 12일
편집: Ismail Qeshta 2017년 11월 12일
Error message is the following:
Error using interp1>reshapeAndSortXandV (line 423)
X and V must be of the same length.
Error in interp1 (line 92)
[X,V,orig_size_v] = reshapeAndSortXandV(varargin{1},varargin{2});
Error in Interpolate (line 15)
x2 = interp1(y3, x3, y2, 'linear');

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 11월 12일
편집: Jan 2017년 11월 12일
The message is clear:
X and V must be of the same length.
Set a breakpoint in the failing line and check the dimensions:
size(y3)
size(x3)
Or:
y = load('Y2.txt');
x = load('X2.txt');
y1 = -sum(y(:,2:11),2);
x1 = x(:,2);
y3 = unique(y1);
x3 = unique(x1);
size(y3)
size(x3)
ans =
5504 1
ans =
5501 1
Then an interpolation is not possible. A solution might be:
[x3, ix] = unique(x1);
y3 = y1(ix);
  댓글 수: 2
Ismail Qeshta
Ismail Qeshta 2017년 11월 12일
Hi Jan,
Yes. You are right. I have just checked it. Do you have any idea on how to solve this issue? Thanks.
a= size(y3)
b= size(x3)
a =
1220 1
b =
1215 1
Ismail Qeshta
Ismail Qeshta 2017년 11월 12일
Thank you very much Jan. Your solution worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by