sum of everything in a column in matlab

To find the sum of everything in a column of a matrix in MATLAB, you can use indexing to select the column and then use the sum() function. Here's an example:

main.m
% Create a matrix
A = [1 2 3; 4 5 6; 7 8 9];

% Select the second column and find the sum
col_sum = sum(A(:,2));
113 chars
6 lines

In this example, the : operator selects all rows, and the 2 specifies the second column. The resulting sum will be stored in the variable col_sum.

gistlibby LogSnag