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 Comments

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 :)

Sign in to comment.

 Accepted Answer

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);

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!