Borrar filtros
Borrar filtros

how to sort the values of each rows in the cell array

2 visualizaciones (últimos 30 días)
jaah navi
jaah navi el 24 de Jun. de 2021
Comentada: jaah navi el 24 de Jun. de 2021
I am having a randomly generated cell array
for example B=15x1 cell array with values in each row of the cell array
1
1
1
1
1
[2,1] - [1,2]
[1,2] - [1,2]
[1,1]
[1,2]
[1,2]
[3,1,2] - [1,2,3]
[3,1,2] - [1,2,3]
[1,3,2] - [1,2,3]
[2,1,1] - [1,1,2]
[3,1,2] - [1,2,3]
here , some rows are not sorted in order. Could anyone please help me how to sort those rows as desired in the right hand size.
As I have randomly generated the rows i want to sort any of the rows as they may change each and every time.

Respuestas (1)

KSSV
KSSV el 24 de Jun. de 2021
If A is your cell array.
B = cellfun(@sort,A,'UniformOutput',false)
  1 comentario
jaah navi
jaah navi el 24 de Jun. de 2021
Thanks. it works and I am getting the following result.
1
1
1
1
1
[1,2]
[1,2]
[1,2]
[1,2]
[1,1]
[1,1,2]
[1,2,2]
[1,2,3]
[1,1,2]
[1,1,2]
Now I want to sort the rows to get the result in the following manner
1
1
1
1
1
[1,1]
[1,2]
[1,2]
[1,2]
[1,2]
[1,1,2]
[1,1,2]
[1,1,2]
[1,2,2]
[1,2,3].
Could you please help me on this.

Iniciar sesión para comentar.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by