Replace the element in the cell array with space inbetween

4 ビュー (過去 30 日間)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015 年 5 月 6 日
コメント済み: Azzi Abdelmalek 2015 年 5 月 6 日
I have a cell array element = {'num riqu' ; 'num riqu' ; 'con tant' ; 'con tant'}
I need to replace num riqu = numeric
con tant = constant
how can I do this ?

採用された回答

Guillaume
Guillaume 2015 年 5 月 6 日
It's not clear how generic of an answer you are looking for. In you particular example, the simplest way would be:
c = {'num riqu' ; 'num riqu' ; 'con tant' ; 'con tant'};
c(strcmp(c, 'num riqu')) = {'numeric'};
c(strcmp(c, 'con tant')) = {'constant'}
  3 件のコメント
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015 年 5 月 6 日
編集済み: Gopalakrishnan venkatesan 2015 年 5 月 6 日
Is it possible with the command regexprep??
Guillaume
Guillaume 2015 年 5 月 6 日
You would have to use one regexprep per expression you want to replace, so while you could do it, it wouldn't be any simpler.
In any case, as defined in your example, the search patterns don't need regular expressions.

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 5 月 6 日
element = {'num riqu' ; 'num riqu' ; 'con tant' ; 'con tant'}
element=strrep(element,'num riqu','numeric');
element=strrep(element,'con tant','constant')
  2 件のコメント
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015 年 5 月 6 日
編集済み: Gopalakrishnan venkatesan 2015 年 5 月 6 日
Is it possible with the command regexprep??
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 5 月 6 日
element = {'num riqu' ; 'num riqu' ; 'con tant' ; 'con tant'}
element=regexprep(element,'num riqu','numeric')
element=regexprep(element,'con tant','constant')
But strrep is faster then regexprep

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

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by