Re: Procedures or (sub)routines



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.
.



Relevant Pages

  • Re: How do I examine a variables content and perform if then fuunctions?
    ... That did the trick, I was referring to them improperly... ... Thanks a ton! ... Sean ...
    (microsoft.public.scripting.vbscript)
  • Re: The cluster resource could not be found...
    ... Try joining the cluster using the "Advanced minimum" configuration. ... usually does the trick for me. ... I am referring issue same mentioned in the following article: ...
    (microsoft.public.windows.server.clustering)
  • Re: change library name of vias in layout
    ... Hi Guys, thanks for the replies. ... I should have stated i was referring ... Stephane, this did the trick for me: ...
    (comp.cad.cadence)
  • Re: Use of scalewidth problems
    ... The keyword "Me" is just a convenient way of referring to an instance of a Class than can have more than one instance, ... You don't really need to use it though because if you leave it out and just type ScaleWidth then in the absence of a specified control VB will assume you are referring to the Form in which that specific line of code "lives". ... The trick is to get the Form to resize itself to its maximized state ...
    (comp.lang.basic.visual.misc)