i need to jump to the begining of the page or to the first loop in the 'end'

hi,
i used the for loop as you can see in the attached image, i need to jump to the begining of the loop
i searched all over the internet but i couldn't find anything
i need index jumping
there is something like that in matlab
and if so, how can i use it?
i tryed using the break command every line before the 'end' it runs perfectly but it's ignoring the change of the index in the for index=1:....
or just to skip the line with the end?....
my cod:
for z_d=0:dz:z;
clc
disp('wait')
disp(length(z_d)-z_d)
for ind_r=1:length(x);
for ind_z=1:length(y);
for scan_recive
r_row=1:length(s);
for scan_reciver_col=1:length(s);
for scan_antena_row=1:length(s_0);
for scan_antena_col=1:length(s_0);
R=s_0(scan_antena_row,scan_antena_col)*(z-z_d)/(z-z_0)+s(scan_reciver_row,scan_reciver_col)*(z_d-z_0)/(z-z_0);
epsilon_new=epsilon_new+A*(exp(-((R-R_t)^2+(z_d-Z_t)^2)/2*a^2))*dz;
epsilon_print(ind_r,ind_z)=epsilon_new;
end
end
end
end
end
end
end

3 Comments

So after you get done with one iteration of the inner most loop (the one over scan_antenna_col) you want to not do any of the other 5 nested for loops and go to iteration #2 of the outermost for loop (the one over z_d)? If so, then why is the loop over z_d the outermost loop instead of the closest one containing the innermost loop over scan_antenna_col?
the problem is that this type of matlab calculation after the inner most loop (line 49) reach to the 'end' it begins to loop right back to the begining (line 47) so the resault is that the most inner loop repeats itself a lot of time, causing the script to take something like 5 minuts to run i need to change each variable at a time
Well yeah. Because that's what you're telling it to do. If you don't want the inner loop to execute a bunch of times, why is it at the center of a bunch of other for loops???

Sign in to comment.

Answers (1)

Each time you begin an iteration of a "for" loop, any change you made to the loop variable will be overridden.
If you need to be able to change values for a loop index, then use a "while" loop.

2 Comments

can you be a little more specific, or give me an example how to use it on my script?
thank you
This will execute 10 times:
for k = 1 : 10
k = 10;
end
This will execute once
k = 1;
while k <= 10
k = 10;
end

Sign in to comment.

Categories

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

Products

Tags

Asked:

on 16 Dec 2013

Commented:

on 17 Dec 2013

Community Treasure Hunt

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

Start Hunting!