problem using for loop

1 view (last 30 days)
Alfonso Maria Ranieri
Alfonso Maria Ranieri on 1 Oct 2020
Answered: Raunak Gupta on 5 Oct 2020
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 Comment
VBBV
VBBV on 2 Oct 2020
Use break statement in the else part of _if_loop and see what result you get

Sign in to comment.

Answers (1)

Raunak Gupta
Raunak Gupta on 5 Oct 2020
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by