matlab刷题,由浅入深(1)
matlab实操案例
·
前言
我是由浅入深的刷题,所有题目就在这一篇文章,我写一个题编辑发布一次,如果你正在看我可能还没来得及更新,还请见谅,我今晚一定出完。
简单的乘法
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,:)=[];
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)