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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by