mManipulating from particular column

Gene T0 T1 T2 T3 T4
'gene1' 'u' 'u' 'd' 'd' 'u'
'gene2' 'u' 'u' 'u' 'u' 'u'
'gene3' 'd' 'd' 'u' 'd' 'd'
'gene4' 'd' 'u' 'd' 'u' 'd'
Taking T0 as reference for gene1 i need to display values which have 'u' for gene1(T0,T1,T4) have 'u',and corresponding column must be displayed for all genes. for ex gene1
'gene1' 'u' 'u' 'u'
'gene2' 'u' 'u' 'u'
'gene3' 'd' 'u' 'd'
'gene4' 'd' 'u' 'd'
for gene3 value is d(T0) so d must be taken
'gene3' 'd' 'd' 'd' 'd'
'gene4' 'd' 'u' 'u' 'd'
I want to display for all gene i have totally 1000 genes ,please help

 채택된 답변

Miro
Miro 2012년 7월 19일

0 개 추천

Something like this:
[n,~] = size(Data);
sgene = 'u'; %searched letter
referencepos = 1; %position of the Row in the Cell matrix of reference gene
s=Data{referencepos,:} == sgene;
Output = {};
Datatmp2 = {};
for i = 1 : n
Datatmp = cell2mat(Data(i,2:end));
Datatmp = Datatmp(s);
for k = 1 : length(Datatmp)
Datatmp2 = [Datatmp2 Datatmp(k)];
end
Datatmp2 = {Data(i,1) Datatmp2}
Output = [Output;Datatmp2 ]
end

댓글 수: 7

Pat
Pat 2012년 7월 20일
Miro i am getting error
Error using == Too many input arguments.
Error in Untitled (line 11) s=Data{referencepos,:} == sgene;
Walter Roberson
Walter Roberson 2012년 7월 20일
s = [Data{referencepos,:}] == sgene;
Pat
Pat 2012년 7월 20일
Miro can you please tell which variable to look for output ,because in Output variable in your above code i did not get the result as i desired.can u please tell
ok so the s should be like this
s=cell2mat(Data(referencepos,:)) == sgene;
Miro
Miro 2012년 7월 20일
편집: Miro 2012년 7월 20일
so if your Datacell is like this:
'gene1' 'u' 'u' 'd' 'd' 'u'
'gene2' 'u' 'u' 'u' 'u' 'u'
'gene3' 'd' 'd' 'u' 'd' 'd'
'gene4' 'd' 'u' 'd' 'u' 'd'
and you want gene1 as reference you set
referencepos = 1; (for gene2 its referencepos = 2 etc.)
with the searched letter 'u', the output will be
'gene1' 'u' 'u' 'u'
'gene2' 'u' 'u' 'u'
'gene3' 'd' 'd' 'd'
'gene4' 'd' 'u' 'd'
you should use Breakpoints in the script to make debugging. For example set a breakpoint within the loop and see how it changes per iteration. Good Luck
Jan
Jan 2012년 7월 20일
@Miro: Use STRCMP to compare cell strings with a string. CELL2MAT and == is not reliable, when the strings have more then 1 character.
Miro
Miro 2012년 7월 20일
what do you mean with reliable? You mean that it sometimes works and sometimes not? Usually i used to use strcmp too, but just rescently i discovered, that booleans also work, which usually are the fastest method to go for.

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

추가 답변 (0개)

카테고리

질문:

Pat
2012년 7월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by