best way to enter only one time in a if block

2 Ansichten (letzte 30 Tage)
Salvatore Mazzarino
Salvatore Mazzarino am 16 Sep. 2012
I have a for cycle
for n= 1: 100
x=rand()*10;
if x > 5
do something
end
end
When I execute this cycle it happens that if x is major than 5, the program enter in if clause. I would create a way that enter in if clause only one time even if the condition is true.which could be the best way?In Java I'd created this using boolean but matlab doesn't have boolean type

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 16 Sep. 2012
Bearbeitet: Azzi Abdelmalek am 16 Sep. 2012
test=0
for n= 1: 100
x=rand()*10;
if x > 5 & test==0
%do something
test=1
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by