Displaying result more than 50%

result =
{6x4 cell}
{5x4 cell}
{4x4 cell}
{3x4 cell}
In which the 4th column has percentage i want to display results having more thab 50 %
the 4th column contains different percentages,i want to display above 50% pleasae help

2 Comments

Azzi Abdelmalek
Azzi Abdelmalek on 4 Sep 2012
Edited: Azzi Abdelmalek on 4 Sep 2012
percentage begins at the seond line? cn you post an example?
Whay is your cell content exactly ? Do you want to display the whole row in which col4 > 50 or just values which are >50 ?

Sign in to comment.

 Accepted Answer

Andrei Bobrov
Andrei Bobrov on 4 Sep 2012
Edited: Andrei Bobrov on 4 Sep 2012
r = result;
for jj = 1:numel(r)
t = cellfun(@(x)isempty(x)|ischar(x),r{jj}(:,end));
t2 = cell2mat(r{jj}(~t,end)) > 50; % corrected 5
if any(t2)
r{jj} = r{jj}([true(nnz(t),1);t2],:);
else
r{jj} = [];
end
end
r = r(~cellfun(@isempty,r),:);
OR
eg
% the initial data
result = {{
'Genes' 'T2&T4' 'T4&T6' []
'YAR029W' 'd' 'd' [60]
'YAR062W' 'ddu' 'ud1' [40]
'YBL095W' 'du' 'ud' [60]};
{
'Genes' 'T2&T4' 'T4&T6' 'ghgh'
'YAR029W' 'd' 'd' [40]
'YAR062W' 'ddu' 'ud1' [40]
'YBL095W' 'du' 'ud' [40]};
{
'Genes' 'T2&T4' 'T4&T6' ''
'YAR029W' 'd' 'd' [40]
'YAR062W' 'ddu' 'ud1' [70]
'YBL095W' 'du' 'ud' [40]}};
% solution
r = result;
for jj = 1:numel(r)
t = cell2mat(r{jj}(2:end,end)) > 50;
if any(t)
r{jj} = r{jj}([true;t],:);
else
r{jj} = [];
end
end
r = r(~cellfun(@isempty,r));

11 Comments

am getting error
Undefined function or method 'gt' for input arguments of type 'cell'.
corrected
Even this code is producing wrong result
corrected 2
corrected 3
Andrei i get following error
??? Error using ==> cell2mat at 47 All contents of the input cell array must be of the same data type.
corrected 4 :)
Thanks andrei i get result but have two problems in the result
1)the values are rearranged as
r =
{6x4 cell}
{5x4 cell}
{4x4 cell}
{1x4 cell}
y do i get {1x4} it displays only the heading and is empty why is it displayed
i get same size if choosen >50,the size must be reduced {1x4} must not be displayed am i correct Andrei
corrected 5, :)
Thans a lot Andrei i gor answer an ver greatful to u

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 4 Sep 2012
Edited: Azzi Abdelmalek on 4 Sep 2012
for k=1:length(result)
A=result{k}
A=A([1 ;find(cell2mat(cellfun(@(x) x>50,A(2:end,4),'uni',false)))+1],:)
out{k}=A
end
%I suppose that your data looks like this
'Genes' 'T2&T4' 'T4&T6' 'perc'
'YAR029W' 'd' 'd' [ 60]
'YAR062W' 'ddu' 'ud1' [ 40]
'YBL095W' 'du' 'ud' [ 60]

14 Comments

getting error
Error using ==> cellfun Non-scalar in Uniform output, at index 2, output 1. Set 'UniformOutput' to false.
my data is in
result{1,1} i have all genes 60%
result{2,1} i have all genes 20%
result{3,1} i have all genes 100%
result{4,1} i have all genes 40%
so only result{1,1} and result{3,1} must be displayed
we have just to make this change
A=A([1 ;find(cell2mat(cellfun(@(x) x>50,A(2:end,4),'uni',false)))+1],:)
and why result{1,1} will not be displayed (60%>50%)
Undefined function or method 'find' for input arguments of type 'cell'.
it's corrected
A=A([1 ;find(cell2mat(cellfun(@(x) x>50,A(2:end,4),'uni',false)))+1],:)
error
Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89 m{n} = cat(1,c{:,n});
can you post sample of your data?
result(from varible editor )
<1001x5 cell>
<1000x5 cell>
<999x6 cell>
<998x5 cell>
<997x6 cell>
result{1,1}
'Genes' 'T0&T2' 'T2&T4' 'T4&T6' []
'YAR029W' 'P' 'P' 'P' 60
'YAR062W' 'PSO' 'SOP' 'PSO' 60
'YAR068W' 'PSO' 'POS' 'SOP' 60
'YBL095W' 'OSP' 'POS' 'PSO' 60
'YBL111C' 'SOP' 'POS' 'SOP' 60
that does not match what you posted in your question. it was about 4 columns
then the change will be
for k=1:length(result)
A=result{k};m=size(A,2)
A=A([1 ;find(cell2mat(cellfun(@(x) x>50,A(2:end,m),'uni',false)))+1],:)
out{k}=A
end
Azzi i think am frustating u a lot am sorry , i am not getting the result
i reduced the data as per
result =
{6x4 cell}
{5x4 cell}
{4x4 cell}
{3x4 cell}
and i tried or code
for k=1:length(result)
A=result{k}
A=A([1 ;find(cell2mat(cellfun(@(x) x>50,A(2:end,4),'uni',false)))+1],:)
out{k}=A
end
i am getting answer ,but the size is altered such as
out=
{4x4 cell}
{5x4 cell}
{6x4 cell}
{3x4 cell}
please help my data consists of only 4 columns
no, try the corrected code without reducing anything
you said to only display some rows with condition, it's obvious sizes will change
i tried Azzi but thee sizes are same why do i get like it as i said it consist of different percentage of values if give >50 the percentage above 50 must be displayed and size must gets reduced,am i correct Azzi
please tell
for the example below what should be the answer
'Genes' 'T0&T2' 'ee' 'T4&T6' 'perc'
'YBR074W' 'du' 'rr' 'du' [ 60]
'YBR138C' 'du' 'rr' 'du' [ 60]
'YBR285W' 'du' 'rr' 'du' [ 40]
% I guess
'Genes' 'T0&T2' 'ee' 'T4&T6' 'perc'
'YBR074W' 'du' 'rr' 'du' [ 60]
'YBR138C' 'du' 'rr' 'du' [ 60]

Sign in to comment.

Categories

Find more on Elementary Math 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!