Why do I get "Array indices must be positive integers or logical values"

J=rand(9);
K=rand(12);
L=rand(10);
a=meshgrid(J,K,L);
sc=3;
[n,m,p0]=size(a);
SI=zeros(n,m,p0);
for ii=1:n
for jj=1:m
td(:,1)=reshape(a(ii,jj,:),p0,1);
if length(td(td>=0))/length(td)~=1
SI(ii,jj,:)=nan;
else
SI(ii,jj,1:sc-1)=nan;
A1=[];
for i=1:sc,
A1=[A1,td(i:length(td)-sc+i)];
end
Y=sum(A1,2);
nn=length(Y);
SI1=zeros(nn,1);
for k=1:12
d=Y(k:12:nn);
Xn=Y(d);
[zeroa]=find(Xn==0);
Xn_nozero=Xn;Xn_nozero(zeroa)=[];
q=length(zeroa)/length(Xn);
parm=gamfit(Xn_nozero);
Gam_xs=q+(1-q)*gamcdf(Xn,parm(1),parm(2));
Z(d)=norminv(Gam_xs);
end
SI1(:,1)=norminv(SI1(:,1));
%output
SI(ii,jj,sc:end)=SI1;

2 commentaires

By the way, I suggest changing
if length(td(td>=0))/length(td)~=1
to
if nnz(td>=0) ~= numel(td)
thank you very much sir! this is a big help for me. i am going to try :)

Connectez-vous pour commenter.

 Réponse acceptée

d=Y(k:12:nn);
Okay, d is a subset of Y.
Xn=Y(d);
And you try to index Y but the subset. But Y contains non-integers.
Perhaps you wanted
d = k:12:nn;
Xn = Y(d);

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by