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

11 ビュー (過去 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 Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by