reindexing a correlation matrix

12 次查看(过去 30 天)
I have a matrix 100x100.
I would like to re-sort the indices of the elements, and re-create the matrix with the new numbering scheme.
showing this as a 3x3 to simplfy my question:
[1 1 1 ; 2 2 2 ; 3 3 3 ]
So that a vector of the element names is 1,2,3,...100.
I want to rename the elements with a new vector, that looks random: 97,5,6... etc
so that I have a new matrix with the new naming arrangement and
so that the value of original element (1,2) will now be the values that was (97,5)
I hope this makes sense. The matrix is not symmetric across the diagonal.
Can someone help me?
thanks
Teena
  3 个评论
teena dobbs
teena dobbs 2019-4-21
Hi
Thanks for the information, but I should have been clearer. And thanks for letting me know about the edit option - did not see it after my original post.
I need to re-index the matrix, not to an actual random order but to a specific order.
Thanks for your help.
Jan
Jan 2019-4-23
@teena dobbs: Of course you can run my code with a specified order also. I used randperm only to produce some meaningful testdata and a valid permutation. Simply insert the wanted permutation in the variable index.
By the way, this resorts the elements, such that the standard indexing method replies teh wanted values. You cannot resort the indices itself. I do not understand your example:
showing this as a 3x3 to simplfy my question:
[1 1 1 ; 2 2 2 ; 3 3 3 ]
So that a vector of the element names is 1,2,3,...100.
Please explain, what the actual problem is and why my suggested code does not solve it.

请先登录,再进行评论。

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2019-4-23
If you want to reindex a correlation matrix you should maintain the correct correlation-structure - so you have to apply the same permutations to the rows and the collumns. Something like this works:
D = randn(50,5);
C = corrcoef(D);
repermidx = [2 3 1 5 4];
C2 = C(:,repermidx);
C2 = C2(repermidx,:);
Cr = corrcoef(D(:,repermidx));
disp(C2-Cr)
Adjust repermidx to suit your needs.
HTH

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by