%Input
A = [1 1 4; 4 4 2; 1 2 4]
%Written out, row sum
out_1 = A(1,:) + A(3,:)
%Using the sum function, row sum
out_2 = sum( A([1 3],:) )
%To get the desired single value, I usually use `sum` twice, like this
out_scalar = sum(sum( A([1 3],:) ))
%But, if you are using 2018b or later, you can do this instead
out_scalar = sum( A([1 3],:) , 'all')
1条答案
按热度按时间eagi6jfj1#
在使用MatLab时,很多工作都是访问数组的行和列。这是一个合理的第一个问题。