Error in Interp1 function when searching for a corresponding matrix

1 visualizzazione (ultimi 30 giorni)
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);

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 24 Lug 2012
Modificato: Andrei Bobrov il 24 Lug 2012
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 Commenti
Yun Inn
Yun Inn il 24 Lug 2012
Thank you very much! I used the second option and it works!
Yun Inn
Yun Inn il 22 Ago 2012
Modificato: Yun Inn il 22 Ago 2012
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.

Accedi per commentare.

Più risposte (1)

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

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by