Fetching data from another column

1 view (last 30 days)
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
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.
Pat
Pat on 27 Aug 2012
walter can u tell wats the solution ,how to solve it please, if it not possible to create variables name its ok ,the output can be stores in any variable as i stated above,i need to perform that output ,please help

Sign in to comment.

Accepted Answer

Andrei Bobrov
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

More Answers (0)

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!