seini
seini

Reputation: 151

Creating, and updating a table or matrix in Matlab

Is it possible to create a matrix or table that is either an empty matrix or a table only of headers. That will add to the bottom row, that is i.e. not overwriting existing data, and not dependent on table/matrix placement indecies.


Example i have and empty matrix

A = []

I now get some data

x = [1 2 3]

I want to update A so that it becomes

A = [1 2 3]

Now, i get even more data

z = 4 5 3

and A becomes

A = [1 2 3,
     4 5 3]

And so forth and so on.

x and z does not exist at the same time.

Upvotes: 2

Views: 178

Answers (2)

articuno
articuno

Reputation: 556

If x and z are row vectors, you can do this by-

A=x;
A=[A;z];
//and so forth

If they are column vectors, you can do-

A=x;
A=[A x];
//and so forth

Upvotes: 1

Sam Roberts
Sam Roberts

Reputation: 24127

Sure. You can say:

>> A = [];
>> x = [1 2 3];
>> z = [4 5 6];

and then to append them you can say

>> A = [A;x]
A =
     1     2     3
>> A = [A;z]
A =
     1     2     3
     4     5     6

Upvotes: 2

Related Questions