iAziz
iAziz

Reputation: 149

matlab: help in ordering cells contents

This is a part of my code that I need to pick one element from input. The very final result is sorted in a strange way that will create 1X2 cells instead of put them next to each other!

  struKm(i).seqNam = cellstr(regexp(data(i).Header, '\s\||\:|\|','split')); % determen the seqance name heads 
  struKm(i).seqNam(cellfun(@(x) isempty(x),struKm(i).seqNam))=[];

This code is in a FOR LOOP.

the result for this code is:

ans =

'AF051909'    '392-397'    'CAGCTG'    '413-418'    'CAGGTG'

some seqNams contain only one Binding site (CAGCTG). for Example:

ans =

'M13483'    '445-450'    'CAACTG'

Now I want to pick the Binding sites only which are (CAGCTG, CAGGTG, CAACTG , ... etc)

I have another for loop that will do it. The code:

struSize = length(struKm); tempcell = cell(1,1);

for m=1:struSize

if (length(struKm(m).seqNam) == 3)
  resultsk.BS{m} = struKm(m).seqNam(3); 
          disp(m);

end
if (length(struKm(m).seqNam) == 5)
 resultsk.BS{m} = cellstr(struKm(m).seqNam([3,5]));
  %tempcell = struKm(m).seqNam([3,5]); resultsk.BS{m} = cellstr(tempcell);
    disp(m);
end

end

and the result for this code:

resultsk.BS{:}

ans =

'CAGCTG'    'CAGGTG'

ans =

'CAACTG'

ans =

'CAACTG'

The problem with some cells that have two binding sites which made the <1x2 cell> next to <1x1 cell>.

I need them all in one row. still struggling with this. Can you please help?

Thank you, A

Upvotes: 0

Views: 74

Answers (1)

angainor
angainor

Reputation: 11810

Thats a very long explanation, but if I understood correctly, only the end is really important

resultsk.BS{1} = {'CAGCTG'    'CAGGTG'};
resultsk.BS{2} = {'CAACTG'};
resultsk.BS{3} = {'CAACTG'};
resultsk.BS{:}  % this gives 'your' answer

Now you can concatenate the cell outputs

A = [resultsk.BS{:}]
A = 

'CAGCTG'    'CAGGTG'    'CAACTG'    'CAACTG'

whos A
 A         1x4               496  cell               

So this is now a 1x4 cell. Is this what you needed?

Upvotes: 1

Related Questions