Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push a variable in a vector in Matlab

Tags:

matlab

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.

like image 560
Manuel Ignacio López Quintero Avatar asked Feb 07 '13 16:02

Manuel Ignacio López Quintero


People also ask

How do you add a value to a vector in MATLAB?

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.

How do you add a value to a matrix in MATLAB?

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.

What does %s mean in MATLAB?

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


1 Answers

I found the answer.

Use this:

A = [A, 7];

Or this:

A(end + 1) = 7;
like image 112
Manuel Ignacio López Quintero Avatar answered Oct 14 '22 11:10

Manuel Ignacio López Quintero