MATLAB: Do the code N times without copying

for loopiterationMATLAB

Hello , I want to run my code then get a result from it then do the code again with the first RESULT only as input. Ps i dont want to copy all the code because it's so long .
example :
enter input1,
THE CODE
RESULT
…….
for i=RESULT-0.5:0.1:RESULT+0.5
THE CODE ;
end
thanks for attention .

Best Answer

Place your code in a function. This can either be in the same file as your main function, or in a different file. Look up functions in the help and check out Doug Hull's videos on MATLAB Central to learn how to use functions. It's one of the most basic things you need to learn, and most people are using them easily after their first few hours of using MATLAB.