simple question on rbgsl vectors

  • Thread starter baptiste Auguié
  • Start date
B

baptiste Auguié

Hi,


I'm trying to do a simple thing : access elements of a vector
specified by their index. In Matlab/Octave i would do,

newVector=oldVector( [1, 3, 56, 72] )

How does this work with Ruby vectors?

oldVector.get(3,4,5) returns the first 3 elements, where I would
expect the 2nd, 3d and 4th.

I've had to do a twisted version of this using arrays and lists,

a2=[]
(0..200).step(10) {|i| a2 << a }

I find it very inefficient and annoying, plus I do need to use
vectors rather than arrays and lists and do not really know how to
convert between these three :(


Oh, and just a quick question: how can i do two instructions in one
block ? I have to repeat the same instructions over and over like
shown below...

a2=[]
b2=[]
(0..200).step(10) {|i| a2 << a }
(0..200).step(10) {|i| b2 << b }

Best regards,

baptiste
 
A

Axel Etzold

Dear Baptiste,

you can get reference for the gsl bindings for ruby
here:

http://rb-gsl.rubyforge.org/ref.html .

oldVector.get(3,4,5) returns the first 3 elements, where I would
expect the 2nd, 3d and 4th.

oldVector.get([3,4,5]) worked for me - I'm not quite sure
why this:
oldVector.get(3,4,5) returns the first 3 elements
happens...



I've had to do a twisted version of this using arrays and lists,

a2=[]
(0..200).step(10) {|i| a2 << a }

I find it very inefficient and annoying, plus I do need to use
vectors rather than arrays and lists and do not really know how to
convert between these three :(


You'll find info about that on the website given above.

Oh, and just a quick question: how can i do two instructions in one
block ? I have to repeat the same instructions over and over like
shown below...

You can use the same index several times:

(0..200).step(10) {|i| a2 << a ; b2<<b }

Best regards,

Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top