- MATLAB does not have any "list" data type. The common MATLAB data types are arrays: numeric, cell, struct, etc.
- [] is an array concatenation operator, not a list operator, as the documentation clearly describes.
- Adding an element to an array can be achieved using indexing or concatenation. What behavior do you expect that you are not seeing?
How to add elements to a list
2,121 views (last 30 days)
Show older comments
I've tried several different options for adding elements to a list, examples:
ls=[]
ls=[ls,element];
Which served only to concatenate the elements that I added, with the same issue happening here:
ls=append(ls,element);
Any other options?
1 Comment
Stephen23
on 16 Jun 2017
Edited: Stephen23
on 16 Jun 2017
The best place to learn about very basic MATLAB concepts, such as what data types there are and how to access them, is to do the introductory tutorials (which are highly recommended for all beginners):
Answers (1)
Walter Roberson
on 16 Jun 2017
ls(end+1) = element;
"Which served only to concatenate the elements that I added"
What behavior are you hoping for that you are not seeing?
2 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!