dim_Bx = 377;
dim_By = 494;
for deg = 1:180
for img_line_B = 1:1000
Co_Bx(img_line_B,1) = img_line_B * cosd(deg) + (dim_Bx/2);
Co_By(img_line_B,2) = img_line_B * sind(deg) + (dim_By/2);
end
Ref_Bx = round(Co_Bx(:,1));
Ref_By = round(Co_By(:,2));
end
Why does Co_By constantly give me 247??
Thanks!!

1 Kommentar

Stephen23
Stephen23 am 12 Jan. 2017
@Brian Cheung: your code is very badly formatted. If you used consistent formatting (e.g. the MATLAB default) then your problem would be a bit easier to identify:
dim_Bx = 377;
dim_By = 494;
for deg = 1:180
for img_line_B = 1:1000
Co_Bx(img_line_B,1) = img_line_B * cosd(deg) + (dim_Bx/2);
Co_By(img_line_B,2) = img_line_B * sind(deg) + (dim_By/2);
end
Ref_Bx = round(Co_Bx(:,1));
Ref_By = round(Co_By(:,2));
end
Now you can clearly see that you have two loop. Think about what the outside loop is doing.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

James Tursa
James Tursa am 12 Jan. 2017

1 Stimme

Because you are constantly overwriting the value assigned to Co_By(img_line_B,2) with a new value because all of this is inside the for deg=1:180 loop. So only the last value sticks, and that last value used deg=180, so sind(180)=0 and the only thing left to assign is the dim_By/2 part (=247).

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 12 Jan. 2017

Kommentiert:

am 12 Jan. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by