Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding zeros in front or at the end of a row?

Status
Not open for further replies.

Morbo

Computer
Nov 26, 2005
1
I'm new to Matlab so have patience.

I am trying to create or find a function that does this (off course for larger rows)

a = [1 3 4 6 7 9]
b = [1 3 4 6 7 9]
c = [1 3 5 9 11 15 7 9]

Now to do this a has to be changed in [1 3 4 6 7 9 0 0] and b to [0 0 1 3 4 6 7 9] so I can do c = a + b. So I create with the function zeros a row [0 0].

Question; How do I add those zeros in front of the row b and at the back of a. I could do it with a loop but that seems like a waste resources. Also if I work with columns how do I add zeros at the top or at the bottom?

thank you in advance.
 
Replies continue below

Recommended for you

In front: a = [zeros(1,3) a];
At the back: a = [a zeros(1,3)];
Top: a = [zeros(size(a)); a];
Bottom: a = [a; zeros(size(a))];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor