Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave basics: How to assign variables from a vector

Tags:

octave

Maybe I'm spoiled by Python, but does Octave allows one to assign the values of variables directly from a vector? That is, doing something like

a,b,c=[5,6,7]

will result with a=5, b=6, c=7. I have tried many combinations of writing the expression above, but no luck yet ...

like image 287
r0u1i Avatar asked Mar 28 '12 13:03

r0u1i


People also ask

How do you input a vector into Octave?

Simply type [1 2 3] at the prompt, followed by enter, and observe the output on the screen). Vector elements can also be entered separated by commas. For example, the command octave#:#> B = [0.1,2,5] will create the row vector B=[0.1 2 5].

How do you declare a variable in Octave?

Variables in Octave do not have fixed types, so it is possible to first store a numeric value in a variable and then to later use the same name to hold a string value in the same program. Variables may not be used before they have been given a value.

How do you access elements in a matrix in Octave?

The dimensions of the matrix : We can find the dimensions of a matrix or vector using the size() function. 2. Accessing the elements of the matrix : The elements of a matrix can be accessed by passing the location of the element in parentheses. In Octave, the indexing starts from 1.


1 Answers

This can be done by constructing a cell array with "{...}" and converting this to a comma separated list via "{:}":

[a b c] = {5 6 7}{:}
a =  5
b =  6
c =  7
like image 161
Christian Avatar answered Dec 31 '22 18:12

Christian