How do I eliminate index error in sum function.
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Time Series Collections 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!