calculating percentage value and cancanating

2 views (last 30 days)
I have values as
gene =
{6x3 cell}
{6x4 cell}
{5x5 cell}
{4x6 cell}
{3x6 cell}
{2x6 cell}
In gene{1,1}
'Genes' 'T0&T2' 'T2&T4' 'T4&T6'
'YAR029W' 'd' 'd' 'd'
'YAR062W' 'du' 'ud' 'du'
'YAR068W' 'du' 'uu' 'uu'
'YBL095W' 'du' 'ud' 'du'
'YBL111C' 'uu' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'ud'
i want to calculate percentage starting from 3rd row
result{1,1}
'Genes' 'T0&T2' 'T2&T4' 'T4&T6' ''
'YAR029W' 'd' 'd' 'd' ''
'YAR062W' 'du' 'ud' 'du' 60
'YAR068W' 'du' 'uu' 'uu' 60
'YBL095W' 'du' 'ud' 'du' 60
'YBL111C' 'uu' 'ud' 'du' 60
'YBL113C' 'uu' 'uu' 'ud' 60
percentage is calclated by (no of rows/5*100)=3/5*100
i tried
emptycells = cell2mat(cellfun(@(x) ~isempty(x),gene,'uni',0));
perempty = sum(emptycells(2:end,2:end),2);
perempty = (perempty./5)*100;
result=[gene(2:end,2:end) perempty]
but get error ,getting all values as zeros

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 3 Sep 2012
result = gene;
for jj = 1:numel(gene)
emptycells = cell2mat(cellfun(@(x) ~isempty(x),result{jj},'un',0));
perempty = sum(emptycells(2:end,2:end),2)./5*100;
result{jj} =[result{jj} [{''};num2cell(perempty)]];
end

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Sep 2012
A={'Genes' 'T0&T2' 'T2&T4' 'T4&T6'
'YAR029W' 'd' 'd' 'd'
'YAR062W' 'du' [] 'du'
'YAR068W' 'du' 'uu' 'uu'
'YBL095W' 'du' 'ud' 'du'
'YBL111C' 'uu' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'ud'};
[n,m]=size(A)
B=cellfun(@(x) ~isempty(x),A)
perc=(sum(B(3:end,2:end),2)/5)*100
A{1,m+1}='perc';
A(3:end,m+1)=num2cell(perc)
  1 Comment
Pat
Pat on 3 Sep 2012
But Azzi i get answer as
gene =
{6x3 cell} 'perc'
{6x4 cell} []
{5x5 cell} [ 0 ]
{4x6 cell} [ 0 ]
{3x6 cell} [ 0 ]
{2x6 cell} [ 0 ]
for variable A above i get answer but for
gene =
{6x3 cell}
{6x4 cell}
{5x5 cell}
{4x6 cell}
{3x6 cell}
{2x6 cell}
i get that error

Sign in to comment.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!