How to delete NaN from column vectors ?

조회 수: 24 (최근 30일)
Thomas Wans
Thomas Wans 2021년 10월 31일
답변: Walter Roberson 2021년 10월 31일
Hi,
I have two coulmn vectors, as you can see some values of y column are NaN and I would like to get rid of them and make it like x1,y1 so when for example second element of y column is NaN, I want also to get rid of the second element in x column
x = [1;2;3;4;5;6;7]
y = [1;NaN,5,NaN,12,15,18]
x1 = [1;3;5;6;7;]
y1 = [1;5;12;15;18]

답변 (1개)

Walter Roberson
Walter Roberson 2021년 10월 31일
x = [1;2;3;4;5;6;7]
x = 7×1
1 2 3 4 5 6 7
y = [1;NaN;5;NaN;12;15;18]
y = 7×1
1 NaN 5 NaN 12 15 18
mask = ~isnan(y);
x1 = x(mask)
x1 = 5×1
1 3 5 6 7
y1 = y(mask)
y1 = 5×1
1 5 12 15 18

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by