×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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.

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

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))];

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources