Error in Interp1 function when searching for a corresponding matrix

조회 수: 1 (최근 30일)
I have eight 1024X1024 matrices corresponding to 8 thicknesses (0,5,10,15,20,25,30,35cm). My code below aims to retrieve a correct matrix for a given thickness, e.g. Th12...
I am getting this error:
??? Error using ==> interp1 at 259 The values of X should be distinct.
Error in ==> Predict_EPIDM at 122 CorrFactor = interp1(col,A,Th);
What is wrong with the code? __________________________________________________________________________
% There are 8 PT 0,5,10,15,20,25,30,35cm
PT=PhysicalThickness;
% A is matrices 1024X1024 for the 8PTs. Size(A) returns 1024X1024X8.
A = cat(3, A{:});
% define the column number nearest to the input Th
Th=12;
colindex=min(find(PT>=Th));
% return the 'in between' A matrix
col=A(:,colindex)+((A(:,colindex)-A(:,colindex-1))*(Th-PT(colindex))/(PT(colindex)-PT(colindex-1)));
% Using the RDepid value to find MUx
CorrFactor = interp1(col,A,Th);

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 7월 24일
편집: Andrei Bobrov 2012년 7월 24일
Let A - cell array your matrices.
A = arrayfun(@(ii)randi(10,5),1:8,'un',0);
Da = cellfun(@(x)x(:),A,'un',0);
Dn = cat(2,Da{:});
Th = [0,5,10,15,20,25,30,35];
PP = arrayfun(@(x)interp1(Th,Dn(x,:),'linear','pp'),(1:size(Dn,1))','un',0);
outfun = @(th)reshape(cellfun(@(x)ppval(x,th),PP),size(A{1}));
outfun(12);
or
t = 12;
idx = find(Th > t,1,'first')-[1 0];
out = diff(cat(3,A{idx}),[],3)/diff(Th(idx))*(t - Th(idx(1)))+A{idx(1)};
  댓글 수: 2
Yun Inn
Yun Inn 2012년 7월 24일
Thank you very much! I used the second option and it works!
Yun Inn
Yun Inn 2012년 8월 22일
편집: Yun Inn 2012년 8월 22일
Andrei,
I chose option 2 of the solution that u gave. If Th remains as [0,5,10,15,20,25,30,35], but 't' is now a matrix, how do I make each pixel search for the right value? Also, some pixels in 't' matrix contain value smaller than 0 and bigger than 35.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 29일
Please review the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by