Info

This question is closed. Reopen it to edit or answer.

How to fix the following: Index exceeds matrix dimensions issue?

1 view (last 30 days)
% image 1:
image = fopen('image1.raw', 'r');
a1 = fread(image,'float32');
p1 = reshape(a1,100,100,100);
j = 0; X1 = 50; Y1 = 50; Z1 = 50;
for i = 1:1:49; j = j+1; mat = 0;
for k = 0:2:358;
x = i*cosd(k);
y = i*sind(k);
Xc = X1+(x/1);
Yc = Y1+(y/1);
XR1 = round(Xc);
YR1 = round(Yc);
mat = mat + p1(XR1,YR1,Z1);
energy = mat/180;
end
D(j,1) = i;
D(j,2) = (energy/(0.0005*0.0005*0.0005*1000));
end
% image 2
image = fopen('image2.raw', 'r');
a2 = fread(image,'float32');
p2 = reshape(a2,100,100,100);
j = 0; X2 = 50; Y2 = 50; Z2 = 50;
for i = 51:5:149; j = j+1;
for k = 0:2:358;
x = i*cosd(k);
y = i*sind(k);
Xc = X2+(x/1);
Yc = Y2+(y/1);
XR2 = round(Xc);
YR2 = round(Yc);
mat = p2(XR2,YR2,Z2); %---------------->>>>>> Index exceeds matrix dimension!!!
energy = mat/180;
end
D(j,1) = i;
D(j,2) = (energy/(0.0015*0.0015*0.0015*1000));
end
  9 Comments
Guillaume
Guillaume on 14 Nov 2018
Could you please explain how XR2 and YR2 becomes 101 and 50?
If you can't figure it out yourself, then I recommend you use the debugger to step through your code one line at a time and see the actual values calculated.This is the most efficient way for you to understand why your program doesn't do what you expected it to do.

Answers (0)

Community Treasure Hunt

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

Start Hunting!