# logical operation on a varable x

1 visualizzazione (ultimi 30 giorni)
Arunachalam D il 3 Lug 2015
Commentato: Star Strider il 3 Lug 2015
For j=1:20
Here if j=1 or j=20 should not proceed further so how to write a code in for loop
End
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Azzi Abdelmalek il 3 Lug 2015
What do you mean?

Accedi per commentare.

### Risposte (3)

Star Strider il 3 Lug 2015
Taking a wild guess:
for k1 = 1:20
if (k1 == 1) | (k1 == 20)
continue
end
% Do Something
end
If k1 is 1 or 20, the loop continues to the next iteration without doing anything after the if block. Otherwise, it continues to do whatever is in the loop.
##### 2 CommentiMostra NessunoNascondi Nessuno
Guillaume il 3 Lug 2015
This, of course, could be simply written as
for k2 = 2:19
%do something
end
So, I'm not sure why the OP is asking the question.
Star Strider il 3 Lug 2015
My guess is that at 1 and 20 it does only one set of operations, and in between, other operations as well. We don’t know the details.

Accedi per commentare.

Hugo il 3 Lug 2015
Is this what you are looking for?
for j = 1:20
if j==1 || j==20, continue; end
your_code_goes_here
end
This executes everything after the if except when j is 1 or 20.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Joep il 3 Lug 2015
You mean something like this because your question is not clear
while stoploop=0
stoploop=j==1|j==20
end
A test you can see it is only true on 1 and 20
for j=1:20
stoploop(j)=j==1|j==20
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by