[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: arugments, more

From: Jonathan King
Subject: Re: arugments, more
Date: Thu, 18 Mar 1999 14:24:59 -0600 (CST)

On Thu, 18 Mar 1999, Daniel Heiserer wrote:

> 1) small thing:
> I have a loop:
> for j=1:100
>       printf("I am at step %d",j);
>       do_some_stuff
> end
> I would like that he printf's at each step he encounters printf.
> Currently he flushes the port, when he did the for loop, but I want
> to know where he is, so I need something like a flush=always or so?
> Does such thing exist? Which way exists?

This is Yet Another Unix Buffering Hose (aka "YAUBH", the sound you make 
when you run into one of these suckers. :-))

Remember that when you're running Octave interactively, your output goes
through a pager, which will usually buffer stuff until Octave is ready
to return to the prompt.  Which is fine in most cases, but not for you.

The answer to your problem is the built-in function "fflush".  Observe:

for i=1:10, 
    # or something slow enough to matter...

Thank me by telling all your friends how great Octave is.

> 2) big thing:
> I have a big problem:

Sigh.  You can also check the mail-list archives for help-octave on
this one.  I'm afraid you're not really going to like the answer.
> I have a function partn:
>  [a11,a12,a21,a22]=partn(A,cp,rp)
>  To partition [A] into [A11], [A12], [A21] and [A22]
> returning 4 arguments IF requested.

And that's the problem here, of course; matlab (and Octave) functions
can't insist on four arguments.  In matlab's case, it's arguably a crappy
design feature; in Octave's, it's the cost of providing bug-for-bug
compatibility. :-(
> I want to return the arguments to reduce_ii
> B=reduce_ii(partn(A,cp,rp));
> function B=reduce_ii(a11,a12,a21,a22);
> reduce_ii NEEDS 4 arguments otherwise it is dead.

If you could break up your call into two lines, everything would be

> For that case I NEED 4 arguments.
> I know I can write something like:
> [a11,a12,a21,a22]=partn(A,cp,rp)
> B=reduce_ii(a11,a12,a21,a22);
> But I would like it in ONE step.

But if you insist...

You'll have to work around it. :-(

One solution is to have partn return a structure with four components (or,
in Octave 2.1, a list with four items, or, in Matlab, a "cell array"
with four items), and have reduce take:

4 arguments when nargin ==4
1 argument, a structure, when nargin ==1

and then unpack the structure within reduce to get your four arguments.

> Is there a way?

It ain't pretty, but it works.  As I mentioned, this has come up on the
Octave-help list before.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]