Double checking a for loop
2 次查看(过去 30 天)
显示 更早的评论
Can someone just double check my for loop. Specifically the bolded line. I wanted to calculate the integrated chlorophyll and then use it to find the relative amount by dividing temp by the intchl. Technically speaking, if I add up all my relative chlorophyll values for each column they should equal 1. However, they are coming out totalling a little over one so I think I messed up.
for i=1:length(databin)
temp=databin{i};
temp=temp(:,Varnum);
VARfield(1:length(temp),i)=temp;
intchl(i) = nansum(0.5.*(temp(1:end -1) + temp(2:end))); %MARKED
%integrated chlorophyll should just be one number for each cast
relchl = temp/intchl(i);
VARfieldrel(1:length(relchl),i)=relchl;
end
0 个评论
回答(1 个)
Sergey Kasyanov
2021-3-13
Hello,
sum(temp/intchl) -> sum(temp)/intchl means that you divide sum of all values by sum of mean values. Lets write it in detail:
sum(temp) = x1 + x2 + x3 + ... + x(n-1) + x(n)
intchl = (x1+x2)/2 + (x2 + x3)/2 + ... + (x(n-2) + x(n-1)/2 + (x(n-1) + xn)/2 = x1/2 + x2 + x3 + .... + x(n-1) + xn/2 = sum(temp) - (temp(1) + temp(end))/2
It means that intchl is lower than sum(temp).
I think you should to calculate intchl as sum(temp).
6 个评论
Sergey Kasyanov
2021-3-15
I cant understand why error still exist. Maybe you should to use diff(bincenters) instead of diff(bincenters')?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!