Do the code N times without copying

1 次查看(过去 30 天)
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 .

采纳的回答

Image Analyst
Image Analyst 2012-4-28
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.
  3 个评论
Image Analyst
Image Analyst 2012-4-29
No, that's not the problem. My programs are typically 3000 - 15000 lines long and have lots of complicated things going on. The problem is you're still learning and just need to try some things. Your Doug function won't work because it's probably just an example or some pseudocode that you were supposed to modify, not take it literally. For example, in an m-file called test1.m you could have this:
function test1() % function name is the same as the m-file name!!
% Now call Doug and put the result into outMain.
outMain = Doug(1,3,5,7,2);
% Now define Doug in the same m-file:
function out = Doug(r, L, N, RN, RR)
var = r + L*N - RN/RR;
rejectionratio = 42 + 69 * exp(pi/123);
out = rejectionratio+(var)
Again, this was just an example and you need to actually put your own code in there, not just take what I did. Even though the code I gave works, it's just gibberish.
Ahmed Hassaan
Ahmed Hassaan 2012-4-30
It wasnt working becuz of clc and clear all in the beginning of the code thanks for ur help :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by