Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
blues
blues 2018년 11월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
% 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
Guillaume
Guillaume 2018년 11월 14일
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 2018년 11월 14일
Thank you Bob and Guillaume for your help and advice.

답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by