MATLAB Answers

calculate data based on previous values and replace it at negative and zeros values

조회 수: 4(최근 30일)
MUKESH KUMAR
MUKESH KUMAR 4 Jul 2018
댓글: MUKESH KUMAR 4 Jul 2018
there is different data in the column in excel (REACTIVE_Y_PH), which has some negative and zeros values also, these values should be replaced by calculating the average of previous data and replace them.

  댓글 수: 5

표시 이전 댓글 수: 2
MUKESH KUMAR
MUKESH KUMAR 4 Jul 2018
can take last 5 or 10 values for average and replace it at zeros or we can directly change -ve values to +ve by sign.
Image Analyst
Image Analyst 4 Jul 2018
What were the "last" 5 values when the first few are to be replaced? There are no elements at indexes -4 to 0. Or did you mean the "last" ones at the other end of the array, like from vec(end-4:end)?
MUKESH KUMAR
MUKESH KUMAR 4 Jul 2018
No, previous values of the column before that value, Like in the image, first 15 values in the second column are negative so make them positive and at 16th row '0' that will be replaced by previous 5 values average((11.5+9.2+9.2+6.9+4.6)/5).Similarly do for next values

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

답변(1개)

KSSV
KSSV 4 Jul 2018
[num,txt,raw] = xlsread('sample.xls') ;
data = cell2mat(cellfun(@str2num,txt(:,2),'un',0)) ;
%%fill negative and zeros
idx = data<=0 ;
data(idx) = NaN ;
data = fillmissing(data,'previous') ;

  댓글 수: 1

MUKESH KUMAR
MUKESH KUMAR 4 Jul 2018
please consider my last comment also,thanks for your support

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

Community Treasure Hunt

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

Start Hunting!

Translated by