Index exceeds matrix dimensions.

1 view (last 30 days)
Seg Ade
Seg Ade on 19 Oct 2014
Answered: Matt J on 19 Oct 2014
I have a set of data: (120,120,60), when reshaped, it gives (120,120,6,10).i.e a group of six data set occurring 10 times. I'm interested in subtracting the last 3 of the six group from the first 3 and again from the next 3 in another group of the next 6 group. My code is as follows:
Freq = [-30 -40 -50 50 40 30]; % offset frequency range
However, I divided the data into a set of 3(s), so that it can be easy to manipulate.
Freq1 = [-30 -40 -50];
ANNe = reshape(ANN,[size(ANN,1), size(ANN,2), length(Freq1),
size(ANN,3)./length(Freq1)]); % reshaping command for 60 images to 6 set of 10 compartment.
for i = 1:size(ANNe_reshape,4) % for loop for 10 compartments
D_minus = ANNe(:,:,1,i+1) + ANNe(:,:,2,i+1) + ANNe(:,:,3,i+1);
ID = ANNe(:,:,1,i) + ANNe(:,:,2,i) +ANNe(:,:,3,i); % adding all the elements
C(:,:,i) =((D_minus-ID)./D_minus);
end
It giving error:
Index exceeds matrix dimensions.
Error in Unti (line 16)
ID_minus = ANN(:,:,1,i+1) + ANNe(:,:,2,i+1) + ANNe(:,:,3,i+1);
Thanks.

Accepted Answer

Matt J
Matt J on 19 Oct 2014
for i = 1:size(ANNe_reshape,4) - 1

More Answers (1)

dpb
dpb on 19 Oct 2014
You've got a bunch of different variable names -- I'm guessing there's the problem.
The error line has two--
Error in Unti (line 16)
ID_minus = ANN(:,:,1,i+1) + ANNe(:,:,2,i+1) + ANNe(:,:,3,i+1)
The first is ANN while the other two refer to ANNe
But your code snippet includes
ANe = reshape(ANN, ...
and
for i = 1:size(ANNe_reshape,4)
which reference two other unique variables which look like
a) a type and
b) something leftover from a previous piece of code, maybe???
Looks like you need to do a serious reading and cleanup of your m-file first.

Community Treasure Hunt

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

Start Hunting!