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 commentaires

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

Connectez-vous pour commenter.

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 4 Sep 2012
Modifié(e) : Andrei Bobrov le 4 Sep 2012

0 votes

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 commentaires

kash
kash le 4 Sep 2012
am getting error
Undefined function or method 'gt' for input arguments of type 'cell'.
Andrei Bobrov
Andrei Bobrov le 4 Sep 2012
corrected
kash
kash le 4 Sep 2012
Even this code is producing wrong result
Andrei Bobrov
Andrei Bobrov le 4 Sep 2012
corrected 2
Andrei Bobrov
Andrei Bobrov le 4 Sep 2012
corrected 3
kash
kash le 4 Sep 2012
Andrei i get following error
??? Error using ==> cell2mat at 47 All contents of the input cell array must be of the same data type.
Andrei Bobrov
Andrei Bobrov le 4 Sep 2012
corrected 4 :)
kash
kash le 4 Sep 2012
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
kash
kash le 4 Sep 2012
i get same size if choosen >50,the size must be reduced {1x4} must not be displayed am i correct Andrei
Andrei Bobrov
Andrei Bobrov le 4 Sep 2012
corrected 5, :)
kash
kash le 4 Sep 2012
Thans a lot Andrei i gor answer an ver greatful to u

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
Modifié(e) : Azzi Abdelmalek le 4 Sep 2012

0 votes

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 commentaires

kash
kash le 4 Sep 2012
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
Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
Modifié(e) : Azzi Abdelmalek le 4 Sep 2012
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%)
kash
kash le 4 Sep 2012
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],:)
kash
kash le 4 Sep 2012
error
Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89 m{n} = cat(1,c{:,n});
Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
can you post sample of your data?
kash
kash le 4 Sep 2012
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
Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
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
kash
kash le 4 Sep 2012
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
Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
no, try the corrected code without reducing anything
Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
you said to only display some rows with condition, it's obvious sizes will change
kash
kash le 4 Sep 2012
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
Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
Modifié(e) : Azzi Abdelmalek le 4 Sep 2012
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]

Connectez-vous pour commenter.

Catégories

En savoir plus sur Elementary Math dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by