problem using for loop

1 次查看(过去 30 天)
Alfonso Maria Ranieri
close all
%key_parameters
a=6396;%startpoint_to_establish_the_lap_modifybytheuser
b=12664;%endpoint_to_establish_the_lap_modifybytheuser
distance=acq.dist(a:b);
Cornersforcycle=zeros(length(distance),1);
Corners=[1861 1920; 1936 2064; 2071 2140; 2161 2272; 2331 2391; 2417 2601; 2645 2791; 2984 3286];
% Corners=[204 340; 379 901; 932 1302; 1389 1972; 2198 2420; 2510 3294; 3455 4066; 4638 5708];
for i=1:length(Corners) <------Is here the error?
for x=1:length(Cornersforcycle) <--------Is here the error?
if distance(x)>=Corners(i,1) && distance(x)<=Corners(i,2)
Cornersforcycle(x)=1;
else
Cornersforcycle(x)=0;
end
end
end
scatter(acq.Track_X(a:b),acq.Track_Y(a:b),5,Cornersforcycle,'filled');
axis auto
grid on
colormap(hsv(2))
colorbar
why the following for loop returns me only the last value? my wish is that the for loop to take the values ​​line by line and not just the last one
  1 个评论
VBBV
VBBV 2020-10-2
Use break statement in the else part of _if_loop and see what result you get

请先登录,再进行评论。

回答(1 个)

Raunak Gupta
Raunak Gupta 2020-10-5
Hi,
Since Corners variable is a matrix, length is probably not the correct function to get the number of elements in particular dimension, you may probably use size. As for the query about last value, I understand that it signifies that only last value in Cornersforcycle is equal to 1. If that is the case, then it is totally dependent on the if condition in the for loop to set the value.
If that doesn’t help, as Vasishta mentioned you can print the intermediate values using disp or can use breakpoints.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by