How to add an element to an array in MATLAB?

I want to add my elemto the end of the array A.

What should I do?

-1
source share
2 answers

Use the following

A = [A elem] % for row array

or

A = [A; elem] % for col array

Edit: Another easy way (as @BenVoigt suggested) to use the endkeyword

A(end+1) = elem;

which works for both row and column vectors.

+5
source

Another way -

A(end+1) = elem;

which works for both row and column vectors.

+5
source

Source: https://habr.com/ru/post/1569057/


All Articles