Matlab - How to sort alphabetically without using sort

 
Vista:

How to sort alphabetically without using sort

Publicado por Cesc (3 intervenciones) el 21/01/2017 19:08:34
Hi, I have a doubt.

I would like to know if is it possible to short alphabetically without using sort. If so, how can be do it?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

How to sort alphabetically without using sort

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 21/01/2017 20:24:08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
clear;
A='FDLERNOPWGAKQMYU'
a=double(A);
n=length(a);
for i=1:n
    for j=1:n-i
        if a(j)>a(j+1)
            aux=a(j);
            a(j)=a(j+1);
            a(j+1)=aux;
        end
    end
end
a=char(a)


1
2
3
4
5
>> ordenar_letras
A =
FDLERNOPWGAKQMYU
a =
ADEFGKLMNOPQRUWY

Saludos.
JOSE JEREMIAS CABALLERO
Asesor de Proyectos con Matlab
Servicios de programación matlab


http://matlabcaballero.blogspot.com
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

How to sort alphabetically without using sort

Publicado por Cesc (3 intervenciones) el 21/01/2017 20:51:05
Thank you for answering Jose Jeremias Caballero

I am most interested in sorting some words as this:

A = 'JIK'
B = 'ABA'
C = 'ABB'
D = 'DGD'

And be able to store them in a file but sorted I mean,
B C D A

As ABA goes before ABB and so on.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

How to sort alphabetically without using sort

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 21/01/2017 21:38:07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
clear;
A = 'JIK';
B = 'ABA';
C = 'ABB';
D = 'DGD';
N={A, B, C, D};
for m=1:length(N)-1
    b=double(N{m});
    c=double(N{m+1});
    n=min([length(b),length(c)]);
    for i=1:n
        for j=1:n
                     if b(j)>c(j)
                         temp=N{m};
                         N{m}=N{m+1};
                         N{m+1}=temp;
                        break;
                end
        end
    end
 
end
N


1
2
3
>> ordenar_palabras
N =
    'ABA'    'ABB'    'DGD'    'JIK'

Greetings..
JOSE JEREMIAS CABALLERO
Project Advisor with Matlab
Matlab programming services


http://matlabcaballero.blogspot.com
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar