newbie argv questions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

newbie argv questions

swest
I am completely new to Octave.  I'm switching from many years of
MathCad.

I'm writing a stand-alone script that passes 2 files on the command
line, but am having some problems with argv.  I've checked the Octave
docs on the website, but cannot find a discussion that answers my
questions.

It appears that I cannot simply open the files with:

load (argv(i,:)), etc  since the length of each string in argv is set
to the maximum length of the longest string in the parameter list.
This causes the appending of extra spaces on the end of arguments that
are shorter--which seems to deny file name matches in glob.

So I am now using:

load (sscanf (argv(i,:), '%s', Inf))  which properly gets just the
non-space string portion of the argument.  Do I really have to do
this?

Now load seems to assign a name to the data array in the file that is
the file name itself.

However, typing  argv(1,:) <CR>

doesn't print the array elements that were in the file, but just the
array name.  How do I print the array elements?

Thanks much--just having some culture shock from MathCad to Octave...

swest





-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: newbie argv questions

Paul Kienzle-5
On Fri, Dec 22, 2000 at 09:35:27PM -0000, [hidden email] wrote:

> I am completely new to Octave.  I'm switching from many years of
> MathCad.
>
> I'm writing a stand-alone script that passes 2 files on the command
> line, but am having some problems with argv.  I've checked the Octave
> docs on the website, but cannot find a discussion that answers my
> questions.
>
> It appears that I cannot simply open the files with:
>
> load (argv(i,:)), etc  since the length of each string in argv is set
> to the maximum length of the longest string in the parameter list.
> This causes the appending of extra spaces on the end of arguments that
> are shorter--which seems to deny file name matches in glob.
>
> So I am now using:
>
> load (sscanf (argv(i,:), '%s', Inf))  which properly gets just the
> non-space string portion of the argument.  Do I really have to do
> this?

load(deblank(argv(i,:)))

>
> Now load seems to assign a name to the data array in the file that is
> the file name itself.
>
> However, typing  argv(1,:) <CR>
>
> doesn't print the array elements that were in the file, but just the
> array name.  How do I print the array elements?

eval(argv(1,:))

or better yet

eval(["v1=",argv(1,:),";"]);

which puts the array in v1 so you don't have to manipulate it with
eval's all the time.  Assignment in Octave is lazy (that is, the array
is only copied if one of the variables referencing it is modified), so
this won't take any extra memory.

>
> Thanks much--just having some culture shock from MathCad to Octave...
>
> swest
>

Paul Kienzle
[hidden email]



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------