MATLAB Answers

SC
1

How to create a list?

Asked by SC
on 9 Feb 2019
Latest activity Answered by Image Analyst
on 9 Feb 2019
Hi,
I want to store numbers in an object A, so that when I call A(i) I can got the i-th element.
But each A(i) may have different length and thus I can't put them in a matrix or array. A list would be preferred, and seems I can't create such an object in Matlab.
How can I proceed? Thanks.

  3 Comments

madhan ravi
on 9 Feb 2019
Illustration with an example would avoid guessing.
SC
on 9 Feb 2019
For example, I want to store [1;3;6], [2;4] and [3] into the same object A, such that when I call A(2), I can get [2;4]. How can I do that?
Stephen Cobeldick on 9 Feb 2019
"How to create a list?"
MATLAB does not have a "list" data class. If you want a container class to hold other arrays, you can use a cell array, a structure, a table, etc.:

Sign in to comment.

Products


Release

R2016a

2 Answers

madhan ravi
Answer by madhan ravi
on 9 Feb 2019

Store it as a cell array:
>> A={[1;3;6], [2;4], [3]}
A =
1×3 cell array
{3×1 double} {2×1 double} {[3]}
>> A{2}
ans =
2
4
>>

  0 Comments

Sign in to comment.


Image Analyst
Answer by Image Analyst
on 9 Feb 2019

Use a cell array. See the FAQ

  0 Comments

Sign in to comment.