replacing the strings with a specific length in a cell

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'

 採用された回答

Oleg Komarov
Oleg Komarov 2012 年 4 月 13 日

1 投票

n = 3;
idx = cellfun('prodofsize',a(:,2)) >= n;
a(idx, 2) = {'m'};
Note, however that cellfun is a concealed loop.

2 件のコメント

FATEMEH
FATEMEH 2012 年 4 月 13 日
Thank you Oleg!
Jan
Jan 2012 年 4 月 14 日
+1: Thanks Oleg! I appreciate that I do not have to post my boring standard comments about the string commands for CELLFUN :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by