Any possibilities of using sortrows for strings

조회 수: 1 (최근 30일)
Salad Box
Salad Box 2019년 5월 20일
댓글: Adam Danz 2019년 5월 21일
Hi,
I have a cell named 'b' consisted of n by 1 of strings, each row in a cell is a string. See below.
The 1,2,3,4 is not b's original order. the original order is a = [3 1 4 2], which means 'hello world' should be in the 1st row, 'hello' should be in the 2nd row, 'world hello' should be in the 3rd row, and 'world' should be in the 4th row.
How to achieve this? How to comebine 'a' and 'b' and by sorting 'a' it also sort 'b'?
Use a table? Matrix? Cell? which one I could apply 'sortrows'?

채택된 답변

Adam Danz
Adam Danz 2019년 5월 20일
편집: Adam Danz 2019년 5월 21일
If I'm understanding correclty, no need for sortrows().
b = {'hello';'world';'hello world';'world hello'};
a = [3 1 4 2];
Resorted
b(a)
ans =
4×1 cell array
{'hello world'}
{'hello' }
{'world hello'}
{'world' }
  댓글 수: 2
Salad Box
Salad Box 2019년 5월 21일
Thanks Adam! That is exactly what I was expecting for!
Adam Danz
Adam Danz 2019년 5월 21일
Glad I could help!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by