Borrar filtros
Borrar filtros

Ordering a column with respect to another column.

2 visualizaciones (últimos 30 días)
Trambak
Trambak el 1 de Abr. de 2014
Comentada: Trambak el 1 de Abr. de 2014
Hi, I have a matrix with 2 columns and N (=50) rows. The columns have positive real numbers. I intend to order the elements of column 1 keeping column 2 fixed so that column 1 and column 2 become oppositely arranged. In other words, keeping column 2 fixed, re-order column 1 so that
corr(column 1, column 2, 'type', 'Kendall') = -1
Any ideas on how I can proceed with this?
Many Thanks!

Respuesta aceptada

lvn
lvn el 1 de Abr. de 2014
Editada: lvn el 1 de Abr. de 2014
This should do it:
A=rand(50,2);
[~,J]=sort(A(:,2),'descend');
A(J,1)=sort(A(:,1),'ascend');
corr(A(:,1), A(:,2) , 'type', 'Kendall')
  2 comentarios
Trambak
Trambak el 1 de Abr. de 2014
Thanks! In this example, you are re ordering both the columns of A. The idea is to keep the arrangement of column 2 unchanged and re arrange column 1 only so that the rank correlation between the re arranged column 1 and the original column 2 is -1.
For example, A = [1 3; 2 5; 3 7; 4 5; 5 10]. I re-arrange only the first column of A without touching the 2nd column of A. I get
B = [5 3; 3 5; 2 7; 4 5; 1 10]
Trambak
Trambak el 1 de Abr. de 2014
Thanks a lot. This works perfectly. I am actually going to try and use this iteratively on an N x 3 matrix and arrange the jth column so that it is oppositely arranged to the sum of the other 2, 1<= j <= 3.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by