How to Append an Element to an Array in Matlab?

I wish to append my elem to the end of an array A.

What should I do?

2

2 Answers

Use the following

A = [A elem] % for row array

or

A = [A; elem] % for col array

Edit: Another simpler way is (as @BenVoigt suggested) to use end keyword

A(end+1) = elem;

which works for both row and column vectors.

5

Another way is

A(end+1) = elem;

which works for both row and column vectors.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest