Fetching data from another column
1 view (last 30 days)
Show older comments
I have 2 data as below
A={
'Genes' 'T0&T2' 'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
'YAR029W' 'dd' 'uu' 'dd' 'uu' 'du'
'YBL095W' 'du' 'ud' 'ud' 'du' 'du'
'YBL111C' 'uu' 'uu' 'ud' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'uu' 'ud' 'ud'
'YBR096W' 'uu' 'uu' 'ud' 'ud' 'dd'
'YBR138C' 'ud' 'ud' 'ud' 'du' 'du' }
B={
'Genes' 'T0&T2' 'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
'YAR029W' 'd' 'u' 'd' 'u' 'd'
'YBL095W' 'd' 'u' 'u' 'd' 'd'
'YBL111C' 'u' 'u' 'u' 'u' 'd'
'YBL113C' 'u' 'u' 'u' 'u' 'u'
'YBR096W' 'u' 'u' 'u' 'u' 'd'
'YBR138C' 'u' 'u' 'u' 'd' 'd' }
i want to fetch the value from B as compared to A as
gene1(or any variable)=
'Genes' 'T0&T2' 'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
'YAR029W' 'd' 'u' 'd' 'u' 'd'
'YBL095W' 'du' 'ud' 'ud' 'du' 'du'
'YBL111C' 'uu' 'uu' 'ud' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'uu' 'ud' 'ud'
'YBR096W' 'uu' 'uu' 'ud' 'ud' 'dd'
'YBR138C' 'ud' 'ud' 'ud' 'du' 'du'
gene2(or any variable)=
'Genes' 'T0&T2' 'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
'YBL095W' 'd' 'u' 'u' 'd' 'd'
'YBL111C' 'uu' 'uu' 'ud' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'uu' 'ud' 'ud'
'YBR096W' 'uu' 'uu' 'ud' 'ud' 'dd'
'YBR138C' 'ud' 'ud' 'ud' 'du' 'du'
as lile this i need to do for all genes in variable B please help
8 Comments
Walter Roberson
on 26 Aug 2012
ismember() will not help you with your difficulty of wanting to create variable names dynamically, wanting to create first gene1, then gene2, and so on.
Accepted Answer
Andrei Bobrov
on 27 Aug 2012
Edited: Andrei Bobrov
on 27 Aug 2012
[~,~,c] = unique(A(2:end,1));
gene = cellfun(@(x,y)[A(1,:);x;A([false,y],:)],num2cell(B(2:end,:),2),num2cell(bsxfun(@lt,c,c'),2),'un',0);
OR
n = size(A,1);
gene = cell(n-1,1)
for jj = 1:n-1
gene{jj} = [A(1,:);B(jj+1,:);A(jj+2:end,:)];
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!