I have a [3 x 3] matrix in Matlab. I want to know for which column the sum of all its elements is the smallest. So specifically, i want to know what the index number is of that column.
I am thinking of doing this with a while loop, but is there a faster (or better) way?
What i’m doing right now is:
columnSum = sum(matrix,2);
minColumn = min(columnSum);
smallestColumn = 0;
columnNumber = 1;
while currentSum ~= minColumn
smallestColumn = columnNumber;
currentSum = columnSum(columnNumber);
columnNumber = columnNumber + 1;
end
If your matrix is called
athen this should do what you want:I’m leaving the office now, so won’t explain further, you should be able to figure it out.