Wrap cell values in single quote so that regexprep works

9 ビュー (過去 30 日間)
Milou
Milou 2012 年 10 月 16 日
My data has strings and digits. It looks something like:
C =
{'N',[0],'Y',[75];
'Y', '75', '0','N'}
When I run
C = regexprep(C,'N','99');
I get 'Error using regexprep: All cells must be strings.'
So, I thought I should wrap everything that isn't a string in single quotes.
I tried:
for i = 1:length(C);
if ~isstr(C{i});
C{i}= sprintf('%d', C{[i]});
end
But it doesnt work. When i change {1} to {1,3} everything that wasn't a string in column 3 becomes a string, but this is inefficient because my data has >600 columns.
What can I do?
Thank you so much for your time and help!

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 10 月 16 日
How about:
C = cellfun(@(x)num2str(x),C,'uni',false)
  2 件のコメント
Matt Fig
Matt Fig 2012 年 10 月 16 日
Milou
Milou 2012 年 10 月 16 日
Thank you!

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 16 日
編集済み: Azzi Abdelmalek 2012 年 10 月 16 日
B= cellfun(@(x) regexprep(char(x),'N','99'),C,'un',0)
  1 件のコメント
Milou
Milou 2012 年 10 月 16 日
Thanks! This works as well, although it truncates the data.

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

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by