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

7 vues (au cours des 30 derniers jours)
Ismail Qeshta
Ismail Qeshta le 12 Nov 2017
Commenté : Ismail Qeshta le 12 Nov 2017
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 commentaire
Ismail Qeshta
Ismail Qeshta le 12 Nov 2017
Modifié(e) : Ismail Qeshta le 12 Nov 2017
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');

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 12 Nov 2017
Modifié(e) : Jan le 12 Nov 2017
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 commentaires
Ismail Qeshta
Ismail Qeshta le 12 Nov 2017
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 le 12 Nov 2017
Thank you very much Jan. Your solution worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by