Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Error??"Subscript indices must either be real positive integers or logicals."

1 visualización (últimos 30 días)
tina jain
tina jain el 19 de Mzo. de 2015
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Error in decalage (line 6) z(1:s-1,1:s-1)=y((p-s+2):p,(p-s+2):p);
Error in reconst_mat (line 51) mrx=decalage(mrx,g1);
%------------------function---------
function [mrx]=reconst_mat(zz1,zz2,zz3,zz4,filter)
%zz1=zz1*2;zz2=zz2*2;zz3=zz3*2;zz4=zz4*2;
[hh1,hh2,gg1,gg2] = wfilters(filter);
[d1,d]=size(hh1);
for i=1:d
h1(i)=hh1(d-i+1);
h2(i)=hh2(d-i+1);
g1(i)=gg1(d-i+1);
g2(i)=gg2(d-i+1);
end
g2 = logical(g2);
g1(g2)
[p1,p2]=size(zz1);
[s1,s2]=size(g1);
k=1;
for i=1:p1
z1(k,:)=zz1(i,:);z1(k+1,:)=0;
z2(k,:)=zz2(i,:);z2(k+1,:)=0;
z3(k,:)=zz3(i,:);z3(k+1,:)=0;
z4(k,:)=zz4(i,:);z4(k+1,:)=0;
k=k+2;
end
m1=mat1(p1*2,p2*2,g1);
m2=mat1(p1*2,p2*2,g2);
y1=m1*z1; y2=m2*z2; y3=m1*z3; y4=m2*z4;
yy1=y1+y2;
yy2=y3+y4;
clear y1 y2 y3 y4
k=1;
for i=1:p2
x1(:,k)=yy1(:,i);x1(:,k+1)=0;
x2(:,k)=yy2(:,i);x2(:,k+1)=0;
k=k+2;
end
clear m1 m2
m1=mat2(p1*2,p2*2,g1);
m2=mat2(p1*2,p2*2,g2);
y1=x1*m1;
y2=x2*m2;
mrx=y1+y2;
mrx=decalage(mrx,g1);
%-----------------function 2-------------------------
function [z]=decalage(y,h)
[s1,s]=size(h); %s1=1, s=10
[p,p]=size(y);% p=4*4
z(1:s-1,1:s-1)=y((p-s+2):p,(p-s+2):p);
z(s:p,s:p)=y(1:(p-s+1),1:(p-s+1));
z(s:p,1:(s-1))=y(1:p-s+1,p-s+2:p);
z(1:s-1,s:p)=y(p-s+2:p,1:p-s+1);
%---------values in this code are as follow-------------------
mrx =
1.0e+03 *
3.5800 1.8740 3.5809 1.9055
2.0416 0.9281 2.0859 1.2452
3.5428 1.9043 3.5232 1.8226
1.7251 1.0687 1.6663 0.7227
g1 =
Columns 1 through 5
0 0 -0.0645 -0.0407 0.4181
Columns 6 through 10
0.7885 0.4181 -0.0407 -0.0645 0
y1 =
-162.1863 18.5793 -161.3208 18.6522
-111.2043 8.3814 -66.9020 12.1164
-147.8071 18.9622 -167.3815 17.3119
-48.3556 11.4247 -107.1290 6.4696
y2 =
1.0e+03 *
3.7422 1.8554 3.7422 1.8868
2.1528 0.9197 2.1528 1.2331
3.6906 1.8853 3.6906 1.8052
1.7735 1.0572 1.7735 0.7162
m1 =
-0.0645 -0.0407 0.4181 0
0 -0.0645 -0.0407 0.4181
0.4181 0 -0.0645 -0.0407
-0.0407 0.4181 0 -0.0645
m2 =
1 1 1 0
0 1 1 1
1 0 1 1
1 1 0 1
y =
1.0e+03 *
3.5800 1.8740 3.5809 1.9055
2.0416 0.9281 2.0859 1.2452
3.5428 1.9043 3.5232 1.8226
1.7251 1.0687 1.6663 0.7227
h =
Columns 1 through 5
0 0 -0.0645 -0.0407 0.4181
Columns 6 through 10
0.7885 0.4181 -0.0407 -0.0645 0
s=10 p=4
please help me to solve the error
  2 comentarios
Guillaume
Guillaume el 19 de Mzo. de 2015
Editada: Guillaume el 19 de Mzo. de 2015
I find it very difficult to read code of such length where the variables are just meaningless one letter characters. I find I constantly have to go back to where the variable has been declared to remember what it is.
I strongly advise you to use longer variable names that have meaning. You may know now what z, s, p, h, etc. stand for, but if you ever have to go back to this code in the future, you'll have a nightmare figuring it out.
Comments in the code would also help greatly.
Guillaume
Guillaume el 19 de Mzo. de 2015
[p,p]=size(y);
You're assigning the number of columns and the number of rows to the same variable p. After that line p will always be the number of columns regardless of the number of rows. Your y matrix is probably square so it does not matter, but to me that screams of a bug waiting to happen.

Respuestas (1)

Guillaume
Guillaume el 19 de Mzo. de 2015
z(1:s-1,1:s-1)=y((p-s+2):p,(p-s+2):p);
For that line to work s must be at least two (so that s-1 >= 1) and p must be at least 2 greater than s (so that p-s+2 >= 1).
According to you p = 4 and s=10, so p-s+2 == -4. That's not a valid index.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by