how do i make a function repeat 10 times.
Mostrar comentarios más antiguos
I worte a code for takeing the avrage of pixels brightness around a pixel and change its value like so:

but now i have to make the code repeat itself on the picture 10 time
how do i do that ?
5 comentarios
Ahmad al-falahi
el 11 de Mayo de 2018
for iteration = 1:10
%...
%code that needs to repeat 10 times
end
What is complicated about that?
Note that your code is a script, not a function.
I can think of 3 ways to do this.
But you need to think about what part of your code you actually want to repeat 10 times, do you want to import your image 10 times?
A)
for ii=1:10
myfunction(myinput)
end
B) A while loop would be working if you pass/return the number of executions.
numberExec=0;
while numberExec<10
numberExec = myfunction(numberExec)
end
inside your function:
function numberExec = myfunction(numberExec)
numberExec=numberExec+1;
%do stuff
end
c) Or use a recursive function:
function myfunction(numberExec)
if numberExec<10
%do stuff
myfunction(numberExec+1)
else
%plot something?
end
Ahmad al-falahi
el 11 de Mayo de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!