Effacer les filtres
Effacer les filtres

Do the code N times without copying

2 vues (au cours des 30 derniers jours)
Ahmed Hassaan
Ahmed Hassaan le 28 Avr 2012
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 .

Réponse acceptée

Image Analyst
Image Analyst le 28 Avr 2012
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 commentaires
Image Analyst
Image Analyst le 29 Avr 2012
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 le 30 Avr 2012
It wasnt working becuz of clc and clear all in the beginning of the code thanks for ur help :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by