Deleting words [ ] and 'neutral'

1 visualizzazione (ultimi 30 giorni)
Pat
Pat il 17 Lug 2012
I have a matrix of values in command window
result=
Columns 1 through 5
'u' 'u' 'd' 'd' 'gene1'
'u' 'u' 'u' 'u' 'gene2'
'd' 'd' 'neutral' 'd' 'gene3'
'd' 'u' 'u' 'u' 'gene4'
'd' 'u' 'd' 'd' 'gene4'
'd' [] [] 'd' 'gene5'
'd' [] [] 'd' 'gene6'
'neutral' 'u' 'u' 'u' 'gene7'
'd' 'u' 'd' 'neutral' 'gene8'
not i want to delete the word 'neutral' and []
please help
[EDITED, Jan, copied from comments]:
i need output as as
'u' 'u' 'd' 'd' 'gene1'
'u' 'u' 'u' 'u' 'gene2'
'd' 'u' 'u' 'u' 'gene4'
'd' 'u' 'd' 'd' 'gene4'
  1 Commento
Jan
Jan il 17 Lug 2012
What exactly does "delete" mean? Do you want the row to disappear, or the column, or that the elements are move to the left and the empty matrix is inserted at the right?
Because the resulting cell matrix must be still rectangular, "delete" is not well defined yet.

Accedi per commentare.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 17 Lug 2012
Modificato: Andrei Bobrov il 17 Lug 2012
EDIT
out = result(all(~cellfun(@(x)isempty(x) | strcmp(x,'neutral'),result),2),:);
or
out = result(~any(cellfun(@(x)isempty(x) | strcmp(x,'neutral'),result),2),:);
  3 Commenti
Andrei Bobrov
Andrei Bobrov il 17 Lug 2012
Modificato: Andrei Bobrov il 17 Lug 2012
My answer was edited.
Jan
Jan il 17 Lug 2012
result(any(cellfun('isempty', result) | strcmp(result, 'neutral')), :) = [];

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by