Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Subscripted assignment dimension mismatch

Subject: Subscripted assignment dimension mismatch

From: sampath

Date: 27 Feb, 2012 13:43:10

Message: 1 of 3

Hi,
The below which i wrote for testing the convolution is showing the error
"Subscripted assignment dimension mismatch.

Error in ==> news at 21
        Ad(i,j)=[(x(2*i+6,j)*h0(8)+x(2*i+6,j+1)*h0(7)+x(2*i+6,j+2)*h0(6)+x(2*i+6,j+3)*h0(5)+x(2*i+6,j+4)*h0(4)+x(2*i+6,j+5)*h0(3)+x(2*i+6,j+6)*h0(2)+x(2*i+6,j+7)*h0(1))*h0(1)..."
I tried to solve the error by following the methods found on internet, but still it's showing the same error. Can someone please help me?
 
clc; clear; close all;
%[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('db4');
disp('2D-DWT N x N matrix')
N=64; temp=1;
for i=1:N
    for j=1:N
        x(i,j)= temp;
        temp=temp+1;
    end
end

x
h0=[-0.0106 0.0329 0.0308 -0.1870 -0.0280 0.6309 0.7148 0.2304];
h1=[-0.2304 0.7149 -0.6309 -0.0280 0.1870 0.0308 -0.0329 -0.0106];

%[A,H,V,D]=dwt2(x,h0,h1);
%C = conv2(x,h0);
for i=1:64/2
    for j=1:64/2
        % disp('2D-DWT Decompoxition of A using formula')
        Ad(i,j)=[(x(2*i+6,j)*h0(8)+x(2*i+6,j+1)*h0(7)+x(2*i+6,j+2)*h0(6)+x(2*i+6,j+3)*h0(5)+x(2*i+6,j+4)*h0(4)+x(2*i+6,j+5)*h0(3)+x(2*i+6,j+6)*h0(2)+x(2*i+6,j+7)*h0(1))*h0(1)...
        +(x(2*i+5,j)*h0(8)+x(2*i+5,j+1)*h0(7)+x(2*i+5,j+2)*h0(6)+x(2*i+5,j+3)*h0(5)+x(2*i+5,j+4)*h0(4)+x(2*i+5,j+5)*h0(3)+x(2*i+5,j+6)*h0(2)+x(2*i+5,j+7)*h0(1))*h0(2)...
        +(x(2*i+4,j)*h0(8)+x(2*i+4,j+1)*h0(7)+x(2*i+4,j+2)*h0(6)+x(2*i+4,j+3)*h0(5)+x(2*i+4,j+4)*h0(4)+x(2*i+4,j+5)*h0(3)+x(2*i+4,j+6)*h0(2)+x(2*i+4,j+7)*h0(1))*h0(3)...
        +(x(2*i+3,j)*h0(8)+x(2*i+3,j+1)*h0(7)+x(2*i+3,j+2)*h0(6)+x(2*i+3,j+3)*h0(5)+x(2*i+3,j+4)*h0(4)+x(2*i+3,j+5)*h0(3)+x(2*i+3,j+6)*h0(2)+x(2*i+3,j+7)*h0(1))*h0(4)...
        +(x(2*i+2,j)*h0(8)+x(2*i+2,j+1)*h0(7)+x(2*i+2,j+2)*h0(6)+x(2*i+2,j+3)*h0(5)+x(2*i+2,j+4)*h0(4)+x(2*i+2,j+5)*h0(3)+x(2*i+2,j+6)*h0(2)+x(2*i+2,j+7)*h0(1))*h0(5)...
        +(x(2*i+1,j)*h0(8)+x(2*i+1,j+1)*h0(7)+x(2*i+1,j+2)*h0(6)+x(2*i+1,j+3)*h0(5)+x(2*i+1,j+4)*h0(4)+x(2*i+1,j+5)*h0(3)+x(2*i+1,j+6)*h0(2)+x(2*i+1,j+7)*h0(1))*h0(6)...
        +(x(2*i,j)*h0(8)+x(2*i,j+1)*h0(7)+x(2*i,j+2)*h0(6)+x(2*i,j+3)*h0(5)+x(2*i,j+4)*h0(4)+x(2*i,j+5)*h0(3)+x(2*i,j+6)*h0(2)+x(2*i,j+7)*h0(1))*h0(7)...
        +(x(2*i-1,j)*h0(8)+x(2*i-1,j+1)*h0(7)+x(2*i-1,j+2)*h0(6)+x(2*i-1,j+3)*h0(5)+x(2*i-1,j+4)*h0(4)+x(2*i-1,j+5)*h0(3)+x(2*i-1,j+6)*h0(2)+x(2*i-1,j+7)*h0(1))*h0(8)];
    end
end
A

Subject: Subscripted assignment dimension mismatch

From: Roger Stafford

Date: 27 Feb, 2012 20:29:14

Message: 2 of 3

"sampath" wrote in message <jig19e$btf$1@newscl01ah.mathworks.com>...
> for i=1:64/2
> for j=1:64/2
> Ad(i,j)=[(x(2*i+6,j)*h0(8)+x(2*i+6,j+1)*h0(7)+x(2*i+6,j+2)*h0(6)+ - - - - - - - - - -
  In your expression for Ad(i,j) I see x(2*i+6,j). If i = 32 this would make 2*i+6 = 70 which is outside the index range of x which you have created. That could cause your error message.

  By the way a more efficient way to create x would be:

 N = 64;
 x = reshape(1:N^2,N,N).';

Roger Stafford

Subject: Subscripted assignment dimension mismatch

From: Barry Williams

Date: 27 Feb, 2012 20:36:10

Message: 3 of 3

"sampath" wrote in message <jig19e$btf$1@newscl01ah.mathworks.com>...
> Hi,
> The below which i wrote for testing the convolution is showing the error
> "Subscripted assignment dimension mismatch.
>
> Error in ==> news at 21
> Ad(i,j)=[(x(2*i+6,j)*h0(8)+x(2*i+6,j+1)*h0(7)+x(2*i+6,j+2)*h0(6)+x(2*i+6,j+3)*h0(5)+x(2*i+6,j+4)*h0(4)+x(2*i+6,j+5)*h0(3)+x(2*i+6,j+6)*h0(2)+x(2*i+6,j+7)*h0(1))*h0(1)..."
> I tried to solve the error by following the methods found on internet, but still it's showing the same error. Can someone please help me?
>
> clc; clear; close all;
> %[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('db4');
> disp('2D-DWT N x N matrix')
> N=64; temp=1;
> for i=1:N
> for j=1:N
> x(i,j)= temp;
> temp=temp+1;
> end
> end
>
> x
> h0=[-0.0106 0.0329 0.0308 -0.1870 -0.0280 0.6309 0.7148 0.2304];
> h1=[-0.2304 0.7149 -0.6309 -0.0280 0.1870 0.0308 -0.0329 -0.0106];
>
> %[A,H,V,D]=dwt2(x,h0,h1);
> %C = conv2(x,h0);
> for i=1:64/2
> for j=1:64/2
> % disp('2D-DWT Decompoxition of A using formula')
> Ad(i,j)=[(x(2*i+6,j)*h0(8)+x(2*i+6,j+1)*h0(7)+x(2*i+6,j+2)*h0(6)+x(2*i+6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)*h0(1))*h0(7)...
> +(x(2*i-1,j)*h0(8)+x(2*i-1,j+1)*h0(7)+x(2*i-1,j+2)*h0(6)+x(2*i-1,j+3)*h0(5)+x(2*i-1,j+4)*h0(4)+x(2*i-1,j+5)*h0(3)+x(2*i-1,j+6)*h0(2)+x(2*i-1,j+7)*h0(1))*h0(8)];
> end
> end
> A

The error probably means as your code loops, you're probably assigning a nonscalar to an address in your matrix. No one is going to go through the above to see where the error is occurring, however. On another note, avoid code like: for i=1:64/2
Remember that in the limits of floating point arithmetic, results of arithmetic do not always evaluate to the expected integer values.
Barry

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us