Matlab基础_1

  1. 1.
p=[2 3 4
   3 4 5
   1 2 3 ]
sum1=cumsum(p,1)
sum2=cumsum(p,2)

cumsum的第二个参数为1或者缺省时,依次计算列元素的和;第二个参数为2时,依次计算行元素的和。


p =

     2     3     4
     3     4     5
     1     2     3


sum1 =

     2     3     4
     5     7     9
     6     9    12


sum2 =

     2     5     9
     3     7    12
     1     3     6
  1. 2.
x=[1 0
   0 5
   1 2
   3 4]
find(x)
find(x,5)
% I = find(X,K,'first') is the same as I = find(X,K).
find(x,5,'last')
find(x>2)

find函数找到矩阵中非零的元素的索引(从第一列开始,到第二列······),第二个参数可选择要多少个非零元素的索引,例子中为5,就输出前5个非零元素的索引,第三个参数可选‘first’或‘last’,表示从前面开始数还是从后面开始数。参数为不等式时,表示输出矩阵中符合不等式的元素的索引。


x =

     1     0
     0     5
     1     2
     3     4


ans =

     1
     3
     4
     6
     7
     8


ans =

     1
     3
     4
     6
     7


ans =

     3
     4
     6
     7
     8


ans =

     4
     6
     8
  1. randperm Random permutation.
    P = randperm(N) returns a vector containing a random permutation(排列) of the
    integers 1:N. For example, randperm(6) might be [2 4 5 6 1 3].

    P = randperm(N,K) returns a row vector containing K unique integers
    selected randomly from 1:N. For example, randperm(6,3) might be [4 2 5].

  2. 4.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值