How do I use regexprep to replace final NaN values in a matrix?

6 ビュー (過去 30 日間)
Derek
Derek 2013 年 3 月 20 日
I have a numeric data stream like this:
NaN NaN NaN 100 102 101 99 102 NaN NaN NaN NaN NaN 101 103 NaN NaN, etc
I'd like to replace the last NaN in each string of NaNs with a zero so it would look like this:
NaN NaN 0 100 102 101 99 102 NaN NaN NaN NaN 0 101 103 NaN NaN
Is this a good regexprep situation or should I do find()?
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 3 月 20 日
regexp is only intended for characters.

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

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 20 日
A=[NaN NaN NaN 100 102 101 99 102 NaN NaN NaN NaN NaN 101 103 NaN NaN]
A(diff(isnan([A 0]))==-1)=0

Jan
Jan 2013 年 3 月 21 日
A = [NaN NaN NaN 100 102 101 99 102 NaN NaN NaN NaN NaN 101 103 NaN NaN];
A(strfind(isnan(A), [true, false]) = 0;

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by