Error in Interp1 function when searching for a corresponding matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 24 Jul. 2012
Bearbeitet: Andrei Bobrov
am 24 Jul. 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 Kommentare
Weitere Antworten (1)
Walter Roberson
am 29 Jul. 2012
Please review the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
0 Kommentare
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!