Re: Procedures or (sub)routines
- From: Perry <reply@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 07:44:32 -0400
Niels,
This maybe not elegant but should do the trick:
loop_flag = true;
while (loop_flag) % Loop while loop_flag==true
if a<2
a = YourProcedure1(a)
elsif a>1 && a<2
a = YourProcedure2(a)
elseif a>2
a = YourProcedure3(a)
else
%============================================
% Default option if above criteria are not met, in this %case
I'll set the loop flag to false to break out of the %loop
%=============================================
loop_flag = false;
end
end
Then you put your procedures that you want carried out depending in
the the outcome of the IF..THEN
%=======================================================
% YourProcedure1
%=======================================================
function return_value = YourProcedure1(a)
return_value = a+2; %as an example
%=======================================================
% YourProcedure2
%=======================================================
function return_value = YourProcedure2(a)
return_value = a/3;
And so on for as many procedures as you need.
Perry
Niels Eernink wrote:
.
Dear all,
In my program I have three if statements, more or less like so:
if (a<1) ...
if (a>1) & (a<2)...
if (a>2) ...
Each if statement should go on to a certain part in my program.
Then
the program should come back to the if statements and check again.
What about making this referred part into a procedure or subroutine
(sorry about the FORTRAN lingo) and then referring to it? Can this
be
done in Matlab? I havent found anything helpful in 'Help'.
I'm also posting this as a new thread.
Niels.
- References:
- Procedures or (sub)routines
- From: Niels Eernink
- Procedures or (sub)routines
- Prev by Date: Re: Plot all results from while-loop simultaneously
- Next by Date: Matlab with NetBeans GUI
- Previous by thread: Procedures or (sub)routines
- Next by thread: Re: Procedures or (sub)routines
- Index(es):
Relevant Pages
|