Error in Interp1 function when searching for a corresponding matrix

1 回表示 (過去 30 日間)
Yun Inn
Yun Inn 2012 年 7 月 24 日
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 Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by