Info

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

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

1 visualización (últimos 30 días)
blues
blues el 13 de Nov. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
% 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 comentarios
Guillaume
Guillaume el 14 de Nov. de 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.
blues
blues el 14 de Nov. de 2018
Thank you Bob and Guillaume for your help and advice.

Respuestas (0)

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