Index exceeds matrix dimensions. where is mistake

3 次查看(过去 30 天)
II=[14 23;44 15];
R=II(:)';
x=0.3;
p=0.343;
for n=2:4;
if x(n-1)>=0 & x(n-1)<=p
x(n)=x(n-1)/p;
else
x(n)=(1-x(n-1))/(1-p);
end
end
A=sort(x);
[A,T]=sort(x);
Y=R(T);
C=reshape(Y,[2,2]);
r = 3.8;
size = 4;
L(1)= 0.234;
for i=2:size
L(i) = r*L(i-1)*(1-L(i-1));
end
mm=min(L);
nn=max(L);
oo=nn-mm;
Z=uint8(8*((L-mm)/oo))+1;
%for i=1:9
%K(i)=mod((abs(L(i))-floor(abs(L(i))))*1e14,50);
%end
CC(1)=bitxor(mod(157,50),mod(Y(1)+Z(1),50));
for i=2:4
CC(i)=bitxor(mod(CC(i-1),50),mod(Y(i)+Z(i),50));
end
X=[12 13 13 14;12 15 16 34;17 18 19 13 ;12 34 32 31];
sX=size(X);
[cA,cH,cV,cD] = dwt2(X,'db4');
subplot(2,2,1);
imagesc(cA);
colormap gray;
title('Approximation');
subplot(2,2,2);
imagesc(cH);
colormap gray;
title('Horizontal');
subplot(2,2,3);
imagesc(cV);
colormap gray;
title('Vertical');
subplot(2,2,4);
imagesc(cD);
colormap gray;
title('Diagonal');
for m=1:2;
for n=1:2;
VV(m,n)=floor(C(m,n)/10);
DD(m,n)=mod(C(m,n),10);
end
end
S = idwt2(cA,cH,VV,DD,'db4',sX);

回答(2 个)

Raj
Raj 2019-7-4
In line number 17 you have defined
size = 4;
which you are using in your 'for' loop at line 19. This variable is clashing with Matlab inbuilt function 'size' which you are trying to use at line 34. Hence you are getting the error. Change the variable name.
  1 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-7-4
编辑:KALYAN ACHARJYA 2019-7-4
Yes @Raj
Size variable name (line 7) is confliting with inbuilt function name.
II=[14 23;44 15];
R=II(:)';
x=0.3;
p=0.343;
for n=2:4;
if x(n-1)>=0 & x(n-1)<=p
x(n)=x(n-1)/p;
else
x(n)=(1-x(n-1))/(1-p);
end
end
A=sort(x);
[A,T]=sort(x);
Y=R(T);
C=reshape(Y,[2,2]);
r = 3.8;
size1 = 4; %%% Issue was here, I have change the variable name size to size1
L(1)= 0.234;
for i=2:size1
L(i) = r*L(i-1)*(1-L(i-1));
end
mm=min(L);
nn=max(L);
oo=nn-mm;
Z=uint8(8*((L-mm)/oo))+1;
%for i=1:9
%K(i)=mod((abs(L(i))-floor(abs(L(i))))*1e14,50);
%end
CC(1)=bitxor(mod(157,50),mod(Y(1)+Z(1),50));
for i=2:4
CC(i)=bitxor(mod(CC(i-1),50),mod(Y(i)+Z(i),50));
end
X=[12 13 13 14;12 15 16 34;17 18 19 13;12 34 32 31];
sX=size(X);
[cA,cH,cV,cD] = dwt2(X,'db4');
subplot(2,2,1);
imagesc(cA);
colormap gray;
title('Approximation');
subplot(2,2,2);
imagesc(cH);
colormap gray;
title('Horizontal');
subplot(2,2,3);
imagesc(cV);
colormap gray;
title('Vertical');
subplot(2,2,4);
imagesc(cD);
colormap gray;
title('Diagonal');
for m=1:2;
for n=1:2;
VV(m,n)=floor(C(m,n)/10);
DD(m,n)=mod(C(m,n),10);
end
end
S = idwt2(cA,cH,VV,DD,'db4',sX);

请先登录,再进行评论。


Aiswarya Subramanian
Hello Sultan,
Could you send the error message? In your code you have initialised x = 0.3, which is a scalar. So x(n-1) will give rise to an error.
Also, after your for loop statement, you have put a semi colon (as shown below)
>> for n=2:4;
Hope this helps :)
  2 个评论
Raj
Raj 2019-7-4
x=0.3 is equivalent to x(1)=0.3 which is what is used while indexing x(n-1) for the first time. So no issue there. It will not give error. Also, semicolon after 'for' loop will not give any error.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-7-4
编辑:KALYAN ACHARJYA 2019-7-4
Also, after your for loop statement, you have put a semi colon (as shown below)
>> for n=2:4;
No @Aiswarya, it does not matter, whether you put or not.
Let's Keep Learning!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by