From: Priyanka Choudhary on 26 Jul 2010 07:36 Hello, I'm using MAT-LAB programming for my project work, and for the same I have to read columns of the various sequences simultaneously in a single array. For that I used the 'fastaread' function and I got my sequences in a matrix as cell array like this Seq=[4x1 char] And when I'm reading this using 'for' loop I'm getting values like this, S=[1x439 char] [1x404 char] [1x404 char] [1x343 char] But instead I want the columns of the sequences used, as like s1=M P I L As, I want to use only the columns for my further calculations. So, Please if anyone can look into my problem. Thank you so much...!
From: us on 26 Jul 2010 07:47 "Priyanka Choudhary" <manipriyanka11(a)gmail.com> wrote in message <i2jrv5$lsa$1(a)fred.mathworks.com>... > Hello, > I'm using MAT-LAB programming for my project work, and for the same I have to read columns of the various sequences simultaneously in a single array. For that I used the 'fastaread' function and I got my sequences in a matrix as cell array like this > > Seq=[4x1 char] > > And when I'm reading this using 'for' loop I'm getting values like this, > > S=[1x439 char] > [1x404 char] > [1x404 char] > [1x343 char] > > But instead I want the columns of the sequences used, as like > s1=M > P > I > L > > As, I want to use only the columns for my further calculations. > So, Please if anyone can look into my problem. > > Thank you so much...! one of the solutions s={ 'abc' 'de' 'fghi' }; ix=2; % <- get second col... r=cellfun(@(x) x(ix),s) %{ % r = b e g %} us
From: Walter Roberson on 26 Jul 2010 17:10 Priyanka Choudhary wrote: > Hello, > I'm using MAT-LAB programming for my project work, and for the same I > have to read columns of the various sequences simultaneously in a single > array. For that I used the 'fastaread' function and I got my sequences > in a matrix as cell array like this > > Seq=[4x1 char] > > And when I'm reading this using 'for' loop I'm getting values like this, > > S=[1x439 char] > [1x404 char] > [1x404 char] > [1x343 char] > > But instead I want the columns of the sequences used, as like > s1=M > P > I > L > > As, I want to use only the columns for my further calculations. > So, Please if anyone can look into my problem. What should happen past 343 when data does not exist for all 4 rows ? The following uses blanks where the row data does not exist: newS = char(S); after which newS(:,K) would be the K'th column
From: Emil on 27 Jul 2010 04:55 us - again an elegant solution r=cellfun(@(x) x(ix),s) and again, I am trying to generalize it a bit further and am stuck. I have a one dim cell array with matrices of different sizes. I.e. ms = {magic(4),magic(2),magic(5)}; From each of those matrices I want to select only certain elements, given by col and row: col = {3,1,4}; row = {[0,1,1,1],[1,0],[0,1,0,0,1]}; Now a generalized form of us's statement should yield r=cellfun(@(x) x(row,col),ms) and uni = 0 of course r{1} = {[10,6,15]}; r{2} = {1}; r{3} = {[14,2]}; Any thoughts are appreciated, thanks
From: us on 27 Jul 2010 05:38
"Emil " <emil4ml(a)gmail.com> wrote in message <i2m6tb$6sa$1(a)fred.mathworks.com>... > us - > > again an elegant solution > r=cellfun(@(x) x(ix),s) > and again, I am trying to generalize it a bit further and am stuck. > > I have a one dim cell array with matrices of different sizes. I.e. > > ms = {magic(4),magic(2),magic(5)}; > > From each of those matrices I want to select only certain elements, given by col and row: > > col = {3,1,4}; > row = {[0,1,1,1],[1,0],[0,1,0,0,1]}; > > Now a generalized form of us's statement should yield > > r=cellfun(@(x) x(row,col),ms) and uni = 0 of course > > r{1} = {[10,6,15]}; > r{2} = {1}; > r{3} = {[14,2]}; > > Any thoughts are appreciated, thanks one of the many solutions - in this case, ARRAYFUN is more appropriate... m={magic(4),magic(2),magic(5)}; cix={3,1,4}; rix={[0,1,1,1],[1,0],[0,1,0,0,1]}; r=arrayfun(@(x) m{x}(find(rix{x}),cix{x}),1:numel(m),'uni',false); r{1}.' % ans = 10 6 15 us |