Insert NaN into specific values

3 ビュー (過去 30 日間)
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2023 年 1 月 7 日
I use this code to insert all the lines in column 4 the numbers equal to 0 equal to NaN, but nothing happens.
That is, I want to insert NaN in all numbers equal to 0 of all rows in column 4.
Does anyone have an idea?
s=load('spi_dca.mat');
spi_dca = s.spi_dca;
mask=spi_dca(:,4)==0;
spi_dca(mask,4)=spi_dca(mask,4)==NaN;

採用された回答

Arif Hoq
Arif Hoq 2023 年 1 月 7 日
try this:
s=load('spi_dca.mat');
spi_dca = s.spi_dca;
col4=spi_dca(:,4);
col4(col4==0)=NaN;
output=[spi_dca(:,[1 2 3]),col4];

その他の回答 (1 件)

Voss
Voss 2023 年 1 月 7 日
s=load('spi_dca.mat');
spi_dca = s.spi_dca;
mask=spi_dca(:,4)==0;
spi_dca(mask,4)=NaN;
  1 件のコメント
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2023 年 1 月 7 日
magnificent!
the code worked perfectly.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by