problem using for loop

1 Ansicht (letzte 30 Tage)
Alfonso Maria Ranieri
Alfonso Maria Ranieri am 1 Okt. 2020
Beantwortet: Raunak Gupta am 5 Okt. 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 Kommentar
VBBV
VBBV am 2 Okt. 2020
Use break statement in the else part of _if_loop and see what result you get

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Raunak Gupta
Raunak Gupta am 5 Okt. 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.

Kategorien

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

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by