whats wrong with the code

1 vue (au cours des 30 derniers jours)
777
777 le 1 Avr 2012
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 commentaires
Jan
Jan le 1 Avr 2012
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 le 1 Avr 2012
You forgot to post some meaningful input values. pf1, pf2, mode?!

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 1 Avr 2012
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.

Community Treasure Hunt

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

Start Hunting!

Translated by