필터 지우기
필터 지우기

problem using sortcols()

조회 수: 9 (최근 30일)
mehdi J
mehdi J 2018년 11월 19일
답변: Jeremy Huard 2023년 1월 31일
Hi everybody, I have a matrix and I want to sort the colums based on the value of a rows. for example consider A:
A =
24 35 46 23 20 31 30 38 37
10 25 15 10 15 15 5 10 5
I want to extract the matrix B as follow:
B =
30 37 24 23 38 46 20 31 35
5 5 10 10 10 15 15 15 25
I've tried to do it with 'sortcols' order but I've faced with this error "Undefined function or variable 'sortcols'".
How could I fix it?
  댓글 수: 1
Stephen23
Stephen23 2018년 11월 19일
편집: Stephen23 2018년 11월 19일
sortcols is in the Bioinformatics Toolbox. Do you have the Bioinformatics Toolbox installed and a valid license for it? Do you have a DataMatrix object (exactly as the sortcols help states that it requires)?
Your example seems to show a double matrix. Why are you trying to use sortrows on a double matrix? Did you read its help?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 19일
A = [ 24 35 46 23 20 31 30 38 37
10 25 15 10 15 15 5 10 5];
import bioma.data.*
DM_A = DataMatrix(A);
B = sortcols(DM_A)
  댓글 수: 2
mehdi J
mehdi J 2018년 11월 19일
what is "bioma.data.*"?
Walter Roberson
Walter Roberson 2018년 11월 19일
The dodocumentation says:
"The DataMatrix constructor function is part of the microarray object package. To make it available, type the following in the MATLAB® command line:
import bioma.data.*
Otherwise, use bioma.data.DataMatrix instead of DataMatrix, in the following syntaxes."
I would suggest that if you are not doing work with the bioinformatics Toolbox that you should not be using sortcols.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jeremy Huard
Jeremy Huard 2023년 1월 31일
Even though there is no sortcols function for double matrices, you could transpose A and use the sortrows function before transposing back:
A = [24 35 46 23 20 31 30 38 37;
10 25 15 10 15 15 5 10 5]
A = 2×9
24 35 46 23 20 31 30 38 37 10 25 15 10 15 15 5 10 5
B = sortrows(A',2)'
B = 2×9
30 37 24 23 38 46 20 31 35 5 5 10 10 10 15 15 15 25

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by