How to create a set subsets?

11 ビュー (過去 30 日間)
Pontus Vikstål
Pontus Vikstål 2018 年 9 月 28 日
編集済み: Stephen23 2018 年 9 月 28 日
How can I create a set S that includes a set of subsets. This is how it would look like in python
S = [[1,4,7],[1,4],[4,5,7],[3,5,6],[2,3,6,7],[2,7]]
What's the correspondence in Matlab?

採用された回答

Stephen23
Stephen23 2018 年 9 月 28 日
編集済み: Stephen23 2018 年 9 月 28 日
Use a cell array:
S = {[1,4,7],[1,4],[4,5,7],[3,5,6],[2,3,6,7],[2,7]}
Cell arrays are the simplest container class in MATLAB, they can store arrays of other classes, of any size. Note that there are two different ways to index a cell array, so read the documentation carefully:
  • {} curly braces access the cell contents.
  • () parentheses access the cells themselves.
MATLAB does not have lists, so forget all about them. MATLAB has arrays of several different classes:
Note that each of your [...] forms one numeric array. It is very important to note that in MATLAB [] is a concatenation operator (and a few other things):
MATLAB does not have a "list" class!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by