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

2 views (last 30 days)
MUKESH KUMAR on 4 Jul 2018
Commented: MUKESH KUMAR on 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.
MUKESH KUMAR on 4 Jul 2018
Edited: MUKESH KUMAR on 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

KSSV on 4 Jul 2018
data = cell2mat(cellfun(@str2num,txt(:,2),'un',0)) ;
%%fill negative and zeros
idx = data<=0 ;
data(idx) = NaN ;
data = fillmissing(data,'previous') ;
MUKESH KUMAR on 4 Jul 2018

### Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!