Search code examples
octave

Octave basics: How to assign variables from a vector


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 ...


Solution

  • 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