MATLAB Answers

Trushit
0

Append rows at the end of Matrix

Asked by Trushit
on 27 Jan 2014
Latest activity Commented on by shubham shinde on 11 Apr 2017

Hi,

a = [1 2 3 ; 4 5 6; 7 8 9]; --> 3x3 matrix

I want to insert at the end number of raws with same elements such as [5 5 5] and make the matrix 10 x 3 i.e. I want to insert 7 more raws with [5 5 5]. Please explain.

  0 Comments

Sign in to comment.

2 Answers

Answer by Amit
on 27 Jan 2014

A = [1 2 3;4 5 6;7 8 9];
A = [A; ones(7,3)*5];

  1 Comment

Thank you. It's short and speedy.

Sign in to comment.


Answer by Azzi Abdelmalek
on 27 Jan 2014
Edited by Azzi Abdelmalek
on 27 Jan 2014

a = [1 2 3 ; 4 5 6; 7 8 9];
b=[5 5 5]  
c=[a;b]% add one row
c=[a;repmat(b,7,1)]  %add 7rows

  2 Comments

Thanks a lot. The answer also helps when we have different elements in stead of all same.

What if I have to insert the row somewhere between middle of the original matrix? Thank you in advance.

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today