Why do I get "Array indices must be positive integers or logical values"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nurul Ain Basirah Zakaria
am 1 Okt. 2020
Kommentiert: Nurul Ain Basirah Zakaria
am 1 Okt. 2020
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 Kommentare
Walter Roberson
am 1 Okt. 2020
By the way, I suggest changing
if length(td(td>=0))/length(td)~=1
to
if nnz(td>=0) ~= numel(td)
Akzeptierte Antwort
Walter Roberson
am 1 Okt. 2020
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);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!