grouping like items in column

1 回表示 (過去 30 日間)
Qiana Curcuru
Qiana Curcuru 2021 年 7 月 12 日
編集済み: Matt J 2021 年 7 月 19 日
I have a cell array that looks like:
a={apples} {1}
{orange} {2}
{apples} {3}
{Pear} {4}
{apples} {5}
I want to get like items together in their own matrix like:
a1= {apples} {1}
{apples} {3}
{apples} {5}
a2= {orange} {2}
a3= {pear} {4}
Thank you!

採用された回答

Matt J
Matt J 2021 年 7 月 12 日
編集済み: Matt J 2021 年 7 月 12 日
One way:
a=sortrows(a,1)
  6 件のコメント
Qiana Curcuru
Qiana Curcuru 2021 年 7 月 19 日
ah okay, but what if i dont know what the categories are since i am writing them with a for loop. is there a way to refernce them using indices?
Matt J
Matt J 2021 年 7 月 19 日
編集済み: Matt J 2021 年 7 月 19 日
fields=fieldnames(Sa);
for i=1:numel(fields)
Sa.(fields{i})
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by