
第一题 Problem 8. Add two numbers
Given a and b, return the sum a+b in c.
返回两数之和。
function c = add_two_numbers(a,b)
c = a+b;
end
第二题 Problem 3.Find the sum of all the numbers of the input vector
Find the sum of all the numbers of the input vector x.
Examples:
Input x = [1 2 3 5]
Output y is 11
Input x = [42 -1]
Output y is 41
返回向量所用元素之和,直接使用sum()即可。
function ans = vecsum(x)
sum(x)
end
注意,原本给的函数的返回变量为y,在此修改为ans,并在计算最终结果时不加分号,能够节省变量空间,很多题都可以这么优化。
第三题 Problem 1702. Maximum value in a matrix
Find the maximum value in

最低0.47元/天 解锁文章
1675

被折叠的 条评论
为什么被折叠?



