필터 지우기
필터 지우기

Sorting the rows of a 2-column matrix based on entries from one column.

조회 수: 1 (최근 30일)
I have a matrix with two columns. The first column is numbers and the second is a string of words. I want to sort the entire matrix in ascending order based on the first column entries and without losing each number's second column pair. A simplified example is as follows:
4 Apple
3 Orange
6 Pear
1 Peach
to
1 Peach
3 Orange
4 Apple
6 Pear
  댓글 수: 2
the cyclist
the cyclist 2017년 6월 16일
A MATLAB matrix cannot hold text. Is this a cell array?
Kyle Reagan
Kyle Reagan 2017년 6월 16일
Whoops, yes it is a cell array. Thanks!

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

채택된 답변

the cyclist
the cyclist 2017년 6월 16일
편집: the cyclist 2017년 6월 16일
C = {4, 'Apple';
3, 'Orange';
6, 'Pear';
1, 'Peach'};
sortrows(C)
ans =
4×2 cell array
[1] 'Peach'
[3] 'Orange'
[4] 'Apple'
[6] 'Pear'
See the documentation for sortrows for details.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by