whats wrong with the code

6 ビュー (過去 30 日間)
777
777 2012 年 4 月 1 日
this is the code to calculate itakura saito distance between two psd. ans should be d but d contains all elements as NaN plss help
[nf1,p2]=size(pf1);
p1=p2-1;
nf2=size(pf2,1);
if nargin<3 | isempty(mode)
mode='0';
end
if any(mode=='d') | (mode~='x' & nf1==nf2)
nx=min(nf1,nf2);
r=pf1(1:nx,:)./pf2(1:nx,:);
q=log(r);
d=log((sum(r(:,2:p1),2)+0.5 * ...
(r(:,1)+r(:,p2)))/p1)-(sum(q(:,2:p1),2)+0.5* ...
(q(:,1)+q(:,p2)))/p1;
else
r=permute(pf1(:,:,ones(1,nf2)),[1 3 2])./permute(pf2(:,:,ones(1,nf1)),[3 1 2]);
q=log(r);
d=log((sum(r(:,:,2:p1),3)+0.5 * ...
(r(:,:,1)+r(:,:,p2)))/p1)-(sum(q(:,:,2:p1),3)+0.5* ...
(q(:,:,1)+q(:,:,p2)))/p1;
end
  2 件のコメント
Jan
Jan 2012 年 4 月 1 日
Please learn how to format the code by reading the "Markup help" link on this page.
Fine. This is the thousands time I've written this suggestion.
Jan
Jan 2012 年 4 月 1 日
You forgot to post some meaningful input values. pf1, pf2, mode?!

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2012 年 4 月 1 日
Just taking a stab in the dark (because I have no idea what this code does), I set
pf1 = rand(10);
pf2 = rand(10);
% And because mode is a reserved function
% that you don't want to override,
% I changed mode to myMode:
myMode = 'x';
and it ran fine with d NOT being all nans.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by