Any possibilities of using sortrows for strings

1 Ansicht (letzte 30 Tage)
Salad Box
Salad Box am 20 Mai 2019
Kommentiert: Adam Danz am 21 Mai 2019
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'?

Akzeptierte Antwort

Adam Danz
Adam Danz am 20 Mai 2019
Bearbeitet: Adam Danz am 21 Mai 2019
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 Kommentare
Salad Box
Salad Box am 21 Mai 2019
Thanks Adam! That is exactly what I was expecting for!
Adam Danz
Adam Danz am 21 Mai 2019
Glad I could help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by