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.
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].
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With