Got Questions? Get Answers.
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:
Index Exceeds Matrix Dimensions

Subject: Index Exceeds Matrix Dimensions

From: Matthew Balint

Date: 11 Oct, 2013 15:45:05

Message: 1 of 1

Hello everyone,

        I am attempting to write a code that takes my 400x400x4 matrix, and average or sum (either or is fine, neither is working at the moment) in 4x4x4 cubes to create, for this example, an output matrix of 100x100, where each value in the 100x100 matrix is the single averaged or summed value for each 4x4x4 cube. I have been working on this for a looooonnggg time and it seems like a simple enough action to do, but I can't figure it out.
 
My code is thus:

A=l6; %400x400 matrix
B=l7; %400x400 matrix
C=l8; %400x400 matrix
D=l9 %400x400 matrix

X=cat(3,A,B,C,D); %concatenated 4D array

k=1:4; %matrix dimensions to loop thru, don't know how/where to use this or if I need to at all

for i=1:100; %my new matrix size??
    j=1:100; %my new matrix size?
    for ii=i+(i-1)*4; %making the 4x4 blocks??
        jj=j+(j-1)*4;
        D(i,j)=sum(sum(X(ii:ii+4,jj:jj+4))); %my new matrix of demensions 100x100???
    end
end

I am now getting an error:

 " ??? Index exceeds matrix dimensions.
Error in ==> nCam_Trial1 at 16
        D(i,j)=sum(sum(X(ii:ii+4,jj:jj+4))); %my new matrix of dimensions 100x100???"


Please help!! If my loop is not correct for what I'm doing in the first place, please let me know! Thanks everyone in advance for your help!

-Matt

Tags for this Thread

No tags are associated with 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