Effacer les filtres
Effacer les filtres

Error in Interp1 function when searching for a corresponding matrix

1 vue (au cours des 30 derniers jours)
Yun Inn
Yun Inn le 24 Juil 2012
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);

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 24 Juil 2012
Modifié(e) : Andrei Bobrov le 24 Juil 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 commentaires
Yun Inn
Yun Inn le 24 Juil 2012
Thank you very much! I used the second option and it works!
Yun Inn
Yun Inn le 22 Août 2012
Modifié(e) : Yun Inn le 22 Août 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.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by