How to create a list?

조회 수: 3,579(최근 30일)
SC
SC 2019년 2월 9일
답변: Image Analyst 2019년 2월 9일
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
Stephen
Stephen 2019년 2월 9일
"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.:

댓글을 달려면 로그인하십시오.

답변(2개)

madhan ravi
madhan ravi 2019년 2월 9일
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
>>

Image Analyst
Image Analyst 2019년 2월 9일
Use a cell array. See the FAQ

제품


릴리스

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by