Discussion:
Using a variable in for-loop as stepsize?
(too old to reply)
Astrid
2012-02-29 11:02:16 UTC
Permalink
Hello!

In a for-loop in the moment I have this:
for k=0:10000:59999
This works.

But I want to give the stepsize 10000 as argv-Parameter.

I call the octave-script and give 5000 as Parameter.
I display it, and it shows the 5000 correct.

But in the loop, which I change to:
for k=0:istepsize:59999
it than takes 53, 106, 159, 212 and so on for the k.

How I have to modify the for-loop, that it works with the correct
parameter?

Regards, Astrid
Christoph Brinkhaus
2012-02-29 19:46:52 UTC
Permalink
Post by Astrid
Hello!
Hello Astrid!
Post by Astrid
for k=0:10000:59999
This works.
But I want to give the stepsize 10000 as argv-Parameter.
As far as I know argv parameter is handled as string.
Post by Astrid
I call the octave-script and give 5000 as Parameter.
I display it, and it shows the 5000 correct.
for k=0:istepsize:59999
it than takes 53, 106, 159, 212 and so on for the k.
The ascii correspondance of 5 is 53.
Post by Astrid
How I have to modify the for-loop, that it works with the correct
parameter?
I think you should convert the string you receive by
the argv parameter to a number by the function str2num().
I hope it helps...
Post by Astrid
Regards, Astrid
Kind regards,

Christoph
Astrid
2012-03-01 09:00:34 UTC
Permalink
Hello!
Post by Christoph Brinkhaus
I think you should convert the string you receive by
the argv parameter to a number by the function str2num().
I hope it helps...
Yes, it did. :)
Thank you very much.

Regards, Astrid

Loading...