0
点赞
收藏
分享

微信扫一扫

matlab刷题,由浅入深(1)


文章目录

  • ​​前言​​
  • ​​简单的乘法​​
  • ​​三角形数​​
  • ​​删除列​​

前言

我是由浅入深的刷题,所有题目就在这一篇文章,我写一个题编辑发布一次,如果你正在看我可能还没来得及更新,还请见谅,我今晚一定出完。

简单的乘法

x 作为您的输入,将其乘以 2 并将结果放入 y。
例如:
matlab刷题,由浅入深(1)_matlab
我的代码:
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.

调用测试:
matlab刷题,由浅入深(1)_matlab_02
注意点:乘法要用点乘

三角形数

三角形数:比如6=1+2+3就是三角形数。
显示三角形为:
matlab刷题,由浅入深(1)_点乘_03
所以题目为:输入四,返回10
matlab刷题,由浅入深(1)_返回结果_04
代码为:
triangle.m

function t = triangle(n)
t=0;
for a=1:n
t=t+a;
end
end

测试:
matlab刷题,由浅入深(1)_matlab_05
考点:主要是一个for循环。

删除列

从输入矩阵A中删除第n列并在输出B中返回结果矩阵。
例如:
matlab刷题,由浅入深(1)_返回结果_06
代码:
创建函数column_remova.m

function B = column_removal(A,n)
A(:,n)=[];
B = A;
end

测试:
matlab刷题,由浅入深(1)_matlab_07
知识点:

删除列用A(:,n)=[];
删除行用A(n,:)=[];


举报

相关推荐

0 条评论