I want to filter values from a data matrix

조회 수: 1 (최근 30일)
Ronald Odongo
Ronald Odongo 2018년 12월 17일
댓글: Ronald Odongo 2018년 12월 17일
I have a datamatrix with the following contents:
Rownames Cond1 Cond1 Cond1 Pvals
a 15 23 21 .055
a 45 1 58 .001
b 8 98 56 .02
c 6 89 45 .004
d 9 55 15 .008
c 45 68 95 .04
I want to filter this matrix to have a matrix like below. The idea is that for any two or more similar row names, i want to remain with the one with the lowest Pvals.
Rownames Cond1 Cond1 Cond1 Pvals
a 45 1 58 .001
b 8 98 56 .02
c 6 89 45 .004
d 9 55 15 .008
  댓글 수: 4
Ronald Odongo
Ronald Odongo 2018년 12월 17일
So, what I need, in case of repeated rownames, are row names with the lowest values in the Pvals column. However, if not repeated then the row itself.
Luna
Luna 2018년 12월 17일
Unfortunately I have never worked on data matrix objects before but the idea of the algorithm may help you below answer.

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

채택된 답변

Luna
Luna 2018년 12월 17일
편집: Luna 2018년 12월 17일
Try this small code below:
dataMatrix = {'Rownames','Cond1', 'Cond1' , 'Cond1', 'Pvals';
'a', 15, 23, 21, .055;
'a', 45, 1, 58, .001;
'b', 8, 98, 56, .02;
'c', 6, 89, 45, .004;
'd', 9, 55, 15, .008;
'c', 45, 68, 95, .04};
sortedDataMatrix = sortrows(dataMatrix(2:end,:),5); % sorts the rows according to 5th column
[~,idx,~] = unique(sortedDataMatrix(:,1)); % get unique values indices
resultMatrix = [dataMatrix(1,:); sortedDataMatrix(idx,:)]; % gets the indexed rows and combine it with data matrix row names(1st row).
  댓글 수: 3
Luna
Luna 2018년 12월 17일
The resultMatrix is what you need isn't it? It doesn't delete the rows you don't want, it sorts the values from lowest the highest first, then gets the unique values of rows(a,b,c,..etc) with this ascending order.
It actually selects the rows you wanted without removing. Please accept answer if it works correctly.
'Rownames' 'Cond1' 'Cond1' 'Cond1' 'Pvals'
'a' 45 1 58 0,001
'b' 8 98 56 0,02
'c' 6 89 45 0,004
'd' 9 55 15 0,008
Ronald Odongo
Ronald Odongo 2018년 12월 17일
Yeah it works. Thank you again!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Management에 대해 자세히 알아보기

제품


릴리스

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by