フィルターのクリア

Sort a matrix according to the index of a vector

2 ビュー (過去 30 日間)
zeu
zeu 2017 年 11 月 20 日
コメント済み: zeu 2017 年 11 月 21 日
I have following labels for the rows and columns of a square matrix:
labels = {'dog', 'car', 'fish'}'
The corresponding matrix that expresses the semantic similarity between the terms is
D = [[0 0.8 0.2];
[0.8 0 0.7];
[0.2 0.7 0]];
I want to sort matrix and labels after following index
idx = [1 2 1];
Sorting the labels is easy:
[values,isort]=sort(idx);
labels_sort = labels(isort)
labels_sort =
3×1 cell array
{'dog' }
{'fish'}
{'car' }
But how can i sort the matrix D accordingly?
  2 件のコメント
KL
KL 2017 年 11 月 20 日
編集済み: KL 2017 年 11 月 20 日
You have created the very same question 3 times. You haven't replied to the comments on your previous posts but just deleted them entirely. Please do not spam the forum, if the answer below is not what you are looking for, provide more information (such as the expected result) and ask follow-up questions.
zeu
zeu 2017 年 11 月 21 日
You are absolutly right. It was my first time a postet a question here. Next time I ll think more before!

サインインしてコメントする。

回答 (1 件)

KL
KL 2017 年 11 月 20 日
編集済み: KL 2017 年 11 月 20 日
if you want to sort the rows of D according to isort, try
newD = D(isort,:)
newD =
0 0.8000 0.2000
0.2000 0.7000 0
0.8000 0 0.7000
  8 件のコメント
zeu
zeu 2017 年 11 月 21 日
編集済み: zeu 2017 年 11 月 21 日
Your answer is unfortunatley not what I m looking for. The indexing array means that the words with the same index belong to the same category. E.g. "dog" and "fish" belong to category 1 (animals), thats why they have the index 1."Car" belongs to category 2 (man-made objects) and has index 2. In the end there will be around 6 different categories and a few hundred terms to sort after them.
zeu
zeu 2017 年 11 月 21 日
Is it possible to solve it by uniting the matrix and the labels into a table and then sorting the table after the labels? Or maybe by using a name-value pair?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by