How do I eliminate index error in sum function.
Show older comments
I have imported a csv file into matlab and want to take the sum of every 48 lines. I have the following lines. When I sum the values I get an error "Index exceeds matrix dimensions". I tried increasing the size of the matrix which alleviated the problem, but I no longer was able to get the correct sum. I also have not define sum or nan sum as a variable in previous lines
clear i j nansum sum
if for i = 1:48:length(dtkp)
h2o_daily(j) = nansum(h2o_mm(i:i+47)); %refer to something outside of matrix?
co2_daily(j) = nansum(co2_mgm2(i:i+47));
h2o_daily_mn(j) = nanmean(h2o_mm(i:i+47)); %mean ignoring nan values
co2_daily_mn(j) = nanmean(co2_mgm2(i:i+47));
dt_daily(j) = min(dtkp(i:i+1));
tallydaily_nanh2o(j) = sum(isnan(h2o_mm(i:i+47)));%count number of nan vales
tallydaily_nanco2(j) = sum(isnan(co2_mgm2(i:i+47)));
j = j+1;
end
Accepted Answer
More Answers (0)
Categories
Find more on Time Series Collections 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!