replacing the strings with a specific length in a cell

8 vues (au cours des 30 derniers jours)
FATEMEH
FATEMEH le 13 Avr 2012
I want to replace the strings with lenght>=3 with 'm' in the second column of the following cell(without using a loop). So I want to get b from a. Any suggestion? thanks a lot
a =
'1' 'aaaa'
'2' 'a'
'3' 'aa'
'4' 'aaa'
b =
'1' 'm'
'2' 'a'
'3' 'aa'
'4' 'm'

Réponse acceptée

Oleg Komarov
Oleg Komarov le 13 Avr 2012
n = 3;
idx = cellfun('prodofsize',a(:,2)) >= n;
a(idx, 2) = {'m'};
Note, however that cellfun is a concealed loop.
  2 commentaires
FATEMEH
FATEMEH le 13 Avr 2012
Thank you Oleg!
Jan
Jan le 14 Avr 2012
+1: Thanks Oleg! I appreciate that I do not have to post my boring standard comments about the string commands for CELLFUN :-)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by