MATLAB Answers

0

Add a row of zeros at the end of the matrix

Asked by Krishma Gold on 20 Sep 2019
Latest activity Edited by the cyclist
on 20 Sep 2019
Grateful for any help
x = [ 23 34 15 19]
actually i want the result to be a 4 by 2
23 0
34 0
15 0
19 0
Need to transpose x first. But unfortuantely I can't get the results.
My codes
new_A=zeros(size(x,1));

  0 Comments

Sign in to comment.

2 Answers

Answer by the cyclist
on 20 Sep 2019
Edited by the cyclist
on 20 Sep 2019

output = [x' zeros(4,1)];
You can generalize this a bit by using the numel function to determine and use the size of x to get the number of zeros, rather than hard-coding the number 4.
output = [x' zeros(numel(x),1)];

  0 Comments

Sign in to comment.


Answer by Kevin Phung on 20 Sep 2019
Edited by Kevin Phung on 20 Sep 2019

x = [23;34;15;19];
new_x = [x zeros(size(x))]

  0 Comments

Sign in to comment.