Hello! I have an array of data where there are zeros and I need to replace them. How can I do this?
data=[100 95 0 90 0 85 0 0 70 65 ] % as it is
data=[100 95 92.5 90 87.5 85 ] % and so it is necessary
is there a special function in matlab for this?

댓글 수: 5

madhan ravi
madhan ravi 2019년 9월 2일
What happened to 0 0 70 65 ??
Lev Mihailov
Lev Mihailov 2019년 9월 2일
I decided not to add them, I thought, and so it will be clear
madhan ravi
madhan ravi 2019년 9월 2일
Provide the complete result for the example provided above, instead of keeping it as a mystery after someone answers.
Well, actually, I need
data=[2 0 1]
data=[2 1.5 1]
Adam
Adam 2019년 9월 2일
I'm guessing you want to replace 0s with the mean of the values either side of them, but as madhan ravi says, if you cut off a fundamental part of the example it's impossible to know. Replacing individual zeros with the mean of values either side is easy. Replacing zeros when you get multiple of them in a row is a little less clearly defined.

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 9월 2일
편집: Andrei Bobrov 2019년 9월 2일

2 개 추천

data=[100 95 0 90 0 85 0 0 70 65 ]';
data(data == 0) = nan;
new_data = fillmissing(data,'linear');
or
ii = (1:numel(data));
lo = data ~= 0;
new_data = interp1(ii(lo),data(lo),ii);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

질문:

2019년 9월 2일

편집:

2019년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by