フィルターのクリア

Replace any string in matrix with NaN

9 ビュー (過去 30 日間)
jnaumann
jnaumann 2013 年 8 月 29 日
I had a previous problem where I wanted to replace any string 'Bad' with NaN.
A forum member suggested the following code which works a treat;
buffer = strrep(buffer, 'Bad', 'NaN') ;
Is there anyway I can modify this so that any string which appears in the matrix is replaced by NaN rather than just the 'Bad'?
Many thanks in advance
Jack
  2 件のコメント
Markus
Markus 2013 年 8 月 29 日
can you give an example of your matrix?
jnaumann
jnaumann 2013 年 8 月 29 日
My measurement file usually inserts bad when a measurement couldn't be made however some floating point have been corrupted and Want to replace these (as well as the 'Bad's with NaN.
For example
Bad Bad Bad -6.54
-6.41 -6.32 -6.01
-6.14 -6.t4 Bad
In this case I want the -6.t4 to be replaced with NaN as well as the Bads

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 29 日
編集済み: Azzi Abdelmalek 2013 年 8 月 29 日
a={'Bad' 'Bad' 'Bad' -6.54; -6.41 -6.32 -6.01 -6.14 ;-6.4 'Bad' 1 2}
b=cellfun(@num2str,a,'un',0);
a(ismember(b,'Bad'))={nan}

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by