フィルターのクリア

How to select the last 6 values in a column?

2 ビュー (過去 30 日間)
Gabriel Luca Pugliese Borges
Gabriel Luca Pugliese Borges 2021 年 7 月 22 日
編集済み: darova 2021 年 8 月 4 日
Hi everyone.
I have a doubt. I need to do some horizontal interpolation and, to do it, i must replace NaN's with 0's (zeros).
I already have done the interpolation with the NaN's in the beginning of the data serie, but my problem starts within the last 6 values.
Here's an example:
To replace the NaN's that appears in the first 6 rows, i made this script:
for c=1:4
x=isnan(DD(1:6,c));
DD(x,c)= 0;
end
And everything went well.
Now, I must replace any NaN that appears in the last 6 rows of all columns. I tried to create a code for it, but it's not working
here it goes:
[row,col,page]=size(DD);
for c=1:4
y=isnan(DD(row-5:row,c));
DD(y,c)=0;
end
Anyone can help me, please?
It's very meaningful to me.

採用された回答

Image Analyst
Image Analyst 2021 年 7 月 22 日
編集済み: Image Analyst 2021 年 7 月 22 日
Why not simply do:
DD(isnan(DD)) = 0;
Or if you really need to replace only nans in the last 6 rows only, and leave the others, you can do
mask = isnan(DD);
mask(1:end-5, :) = false; % Ignore all up to the 6th row from the bottom by setting the mask to false there.
DD(mask) = 0;
To set nans to 0 in the first 6 rows:
mask = isnan(DD);
mask(7:end, :) = false; % Ignore all rows after the 6th row.
DD(mask) = 0;
Or to do the first 6 and last 6 all in one operation:
mask = isnan(DD);
mask(7:end-5, :) = false; % Ignore middle rows.
DD(mask) = 0;
  1 件のコメント
Gabriel Luca Pugliese Borges
Gabriel Luca Pugliese Borges 2021 年 8 月 4 日
Perfect, my friend. Thanks a lot for your help, appreciate it!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by