The sum function in Fortran sums all of the elements in the array. The / operation in Fortran is an element-wise divide. I.e., for arrays X and Y of the same size
Fortran Equivalent MATLAB
------- -----------------
sum(X) sum(X(:))
X / Y X ./ Y
X * Y X .* Y
The X(:) simply returns X reshaped into a column vector. So in your case, if you wanted it all on one line, the equivalent code would be:
Fortran Equivalent MATLAB
------- -----------------
sum(A(:,:,:,:,:,1))/sum(A(:,:,:,:,:,2)) sum(reshape(A(:,:,:,:,:,1),[],1))./sum(reshape(A(:,:,:,:,:,2),[],1))
Note: The result of the sums on the MATLAB code are scalars, so I could have used / instead of ./
Best Answer