whats wrong with the code

1 visualizzazione (ultimi 30 giorni)
777
777 il 1 Apr 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 Commenti
Jan
Jan il 1 Apr 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 il 1 Apr 2012
You forgot to post some meaningful input values. pf1, pf2, mode?!

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 1 Apr 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