필터 지우기
필터 지우기

Straight line approximation of elements in array

조회 수: 4 (최근 30일)
Pesach Nestlebaum
Pesach Nestlebaum 2022년 3월 22일
편집: Matt J 2022년 3월 22일
I have a 21x1 array in which every other value is NaN:
s=[0 NaN 5 NaN 0 NaN 0 NaN 5 NaN 0 NaN 0 NaN 5 NaN 0 NaN 0 NaN 5];
I need to make a straight line from one surrounding value to the other for each NaN. For this case, it would be the averages, like 0 NaN 5 would be 2.5, because the surrounding values are 0 and 5, which would make the NaN become 2.5.
Basically I need to replace all the NaNs in this fashion and plot the new array.

채택된 답변

Matt J
Matt J 2022년 3월 22일
편집: Matt J 2022년 3월 22일
s=[0 NaN 5 NaN 0 NaN 0 NaN 5 NaN 0 NaN 0 NaN 5 NaN 0 NaN 0 NaN 5];
fillmissing(s,'linear')
ans = 1×21
0 2.5000 5.0000 2.5000 0 0 0 2.5000 5.0000 2.5000 0 0 0 2.5000 5.0000 2.5000 0 0 0 2.5000 5.0000
  댓글 수: 5
Pesach Nestlebaum
Pesach Nestlebaum 2022년 3월 22일
Execution of script fillmissing as a function is not supported:
C:\Users\hipes\Downloads\fillmissing.m
Error in sf (line 2)
fillmissing(s,'linear')
Matt J
Matt J 2022년 3월 22일
편집: Matt J 2022년 3월 22일
Did you download an mfile called fillmissing.m to the folder
C:\Users\hipes\Downloads\
If you aren't using it for something else, I suggest you get rid of it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by