Hi,
I have a set of data to be interpolated for two files. I could use the code below when the second file (representing Y axis) has 11 columns.
However, when the second file (representing Y axis) has only two columns, it shows the following error:
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 151)
F = griddedInterpolant(X,V,method);
Error in File11 (line 18)
x2 (k,:) = interp1(y3, x3, A(:,i), 'linear');
clear; clc;
Folder = cd;
N=1;
x2 = zeros(N, 10);
for k = 1:N;
Driftt = sprintf('Drift%d.out', k);
Reactt = sprintf('React%d.out', k);
matDrift = importdata(fullfile(Folder, Driftt));
matReact = importdata(fullfile(Folder, Reactt));
x1= matDrift(:,2);
y1= -matReact(:,2);
[x3, ix] = unique(x1);
y3 = y1(ix);
A=dlmread('result_all.txt');
for i=1:size(A,2)
x2 (k,:) = interp1(y3, x3, A(:,i), 'linear');
temp=x2(k,:);
temp(isnan(temp))=0.05;
x2(k,:)=temp;
fid=fopen(['result_' num2str(i) '.txt'],'a');
fprintf(fid,'%f\n',x2(k,:));
fclose(fid);
end
end

댓글 수: 1

Ismail Qeshta
Ismail Qeshta 2019년 2월 20일
I have just tried to use "unique" with y3, but I got the following error:
Error using interp1>reshapeAndSortXandV (line 424)
X and V must be of the same length.
Error in interp1 (line 93)
[X,V,orig_size_v] = reshapeAndSortXandV(varargin{1},varargin{2});
Error in File11 (line 19)
x2 (k,:) = interp1(y3, x3, A(:,i), 'linear');

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

답변 (1개)

Matt J
Matt J 2019년 2월 19일
편집: Matt J 2019년 2월 19일

0 개 추천

interp1 is complaining that y3 has repeated elements. They are required to be unique and monotonic.

댓글 수: 3

Ismail Qeshta
Ismail Qeshta 2019년 2월 19일
편집: Ismail Qeshta 2019년 2월 20일
Hi Matt,
Many thanks for your reply. Aren't they unique?
Nope.
K>> numel(y3)
ans =
267
K>> numel(unique(y3))
ans =
266
Ismail Qeshta
Ismail Qeshta 2019년 2월 20일
Thanks Matt.
Would it be possible to ask how to incorporate this into my code?

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

카테고리

도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2019년 2월 19일

댓글:

2019년 2월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by