Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I append to a vector in Octave?

When ever I have to append to a vector I am doing this.

A = [2 3 4] A = [A; 3 4 5] 

I was wondering if there are any inbuilt functions for this or more elegant ways of doing this in Octave.

like image 306
Aditya Avatar asked Jun 13 '14 03:06

Aditya


People also ask

How do you access an element in a vector in 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].


1 Answers

The builtin functions are cat, vertcat, and horzcat, found on pages 380-381 of the Octave documentation (v 3.8). They are essentially equivalent to what you have though.

octave:5> A = [2 3 4]; octave:6> A = [A; 3 4 5] A =     2   3   4    3   4   5  octave:7> B = [4 5 6]; octave:8> B = vertcat(B,[5 6 7]) B =     4   5   6    5   6   7 

Another (again equivalent) way would be to directly use matrix indexing (see page 132)

octave:9> C = [6 7 8]; octave:10> C(end+1,:) = [7 8 9] C =     6   7   8    7   8   9 
like image 152
user3288829 Avatar answered Sep 28 '22 23:09

user3288829