matlab cody学习笔记 day3

一些心得:
(1)将矩阵A的n列删除的一种简单方法:
A(:,n)=[];
不需要循环即可解决。
(2)matlab里面可以定义字母,例如a=‘yes’;
(3)三角数这个题目很有意思:
Triangle numbers are the sums of successive integers. So 6 is a triangle number because
6 = 1 + 2 + 3
which can be displayed in a triangular shape like so
*
* *
* * *
Thus 6 = triangle(3). Given n, return t, the triangular number for n.
Example:
Input n = 4
Out t=10
我的解决方案是:
function t = triangle(n)
t=0
for i= 1:n
t=t+i;
end
但有种更简单的语句,把matlab的数组运算的强项发挥的很好:t = sum(1:n);

猜你喜欢

转载自blog.csdn.net/yxnooo1/article/details/112556549