How to push a variable in a vector in Matlab?
Something like this:
A = [5 2 3];
push(A, 7);
% A = [5 2 3 7]
Thanks.
To append an element to a vector just specify a value at the desired position. If it is not the next consecutive position, MATLAB pads the elements in between with zeros. You can append existing vectors to each other if they are all row vectors or all column vectors.
You can add one or more elements to a matrix by placing them outside of the existing row and column index boundaries. MATLAB automatically pads the matrix with zeros to keep it rectangular. For example, create a 2-by-3 matrix and add an additional row and column to it by inserting an element in the (3,4) position.
%s represents character vector(containing letters) and %f represents fixed point notation(containining numbers). In your case you want to print letters so if you use %f formatspec you won't get the desired result.
I found the answer.
Use this:
A = [A, 7];
Or this:
A(end + 1) = 7;
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