Borrar filtros
Borrar filtros

Do the code N times without copying

2 visualizaciones (últimos 30 días)
Ahmed Hassaan
Ahmed Hassaan el 28 de Abr. de 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 .

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by