文章目录
前言
- 前言
- 简单的乘法
- 三角形数
- 删除列
我是由浅入深的刷题,所有题目就在这一篇文章,我写一个题编辑发布一次,如果你正在看我可能还没来得及更新,还请见谅,我今晚一定出完。
简单的乘法x 作为您的输入,将其乘以 2 并将结果放入 y。 例如: 我的代码: times2.m
function y = times2(x) % Do not edit this line.
% Modify the line below so that the output y is twice the incoming value x
y = 2.*x;
% After you modify the code, press the "Submit" button, and you're on your way.
end % Do not edit this line.
调用测试: 注意点:乘法要用点乘
三角形数:比如6=1+2+3就是三角形数。 显示三角形为: 所以题目为:输入四,返回10
代码为: triangle.m
function t = triangle(n)
t=0;
for a=1:n
t=t+a;
end
end
测试: 考点:主要是一个for循环。
从输入矩阵A中删除第n列并在输出B中返回结果矩阵。 例如: 代码: 创建函数column_remova.m
function B = column_removal(A,n)
A(:,n)=[];
B = A;
end
测试: 知识点:
删除列用A(:,n)=[];
删除行用A(n,:)=[];