フィルターのクリア

Do the code N times without copying

2 ビュー (過去 30 日間)
Ahmed Hassaan
Ahmed Hassaan 2012 年 4 月 28 日
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 Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by