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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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