zoukankan      html  css  js  c++  java
  • Matlab函数

    any() 相当于或操作,只要有1,就返回1

    all() 相当于与操作,只要有0,就返回0

     C = union(A,B):

     C为A和B的并集。去掉相同元素。

    C = intersect(A,B)

    C为A和B的交集. The values of C are in sorted order.

    [Lia,Locb] = ismember(A,B):

      判断A中元素是否为B中的子元素,如果不是则,Lia和Locb中元素值都为0(注意,Lia大小和A一样,Locb大小和B一样)。如果A中有元素是B中的,在Lia中对应返回值1,Locb, containing the highest index in B for each value in A that is a member of B. The output array, Locb, contains 0 wherever A is not a member of B.

    [C,ia] = setdiff(A,B):

      返回的C元素为在A中出现,但是没有在B中出现,ia为其索引值,满足C = A(ia)。

    D = D(:)'; % ensure that D is a row vector

    D(:)按列将矩阵变为列向量

     

    reshape是根据原来的矩阵创造新的矩阵,repmat是将原来的矩阵复制多次,构成一个大矩阵。

    >> A=magic(4)

    A =

    16 2 3 13

    5 11 10 8

    9 7 6 12

    4 14 15 1

    B = reshape(A,...,[],...) calculates the length of the dimension represented by the placeholder [], such that the product of the dimensions equals prod(size(A)). The value of prod(size(A)) must be evenly divisible by the product of the specified dimensions. You can use only one occurrence of [].

    >> reshape(A,[],2)

    ans =

    16 3

    5 10

    9 6

    4 15

    2 13

    11 8

    7 12

    14 1

    max(a),若a为向量,返回最大值,若a为矩阵,返回每列最大值作为一个向量。

    C = max(A,B) returns an array the same size as A and B with the largest elements taken from A or B. The dimensions of A and B must match, or they may be scalar.

    C = max(A,[],dim) returnsthe largest elements along the dimension of A specifiedby scalar dim. For example, max(A,[],1) producesthe maximum values along the first dimension of A.

    [C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.

    K>> c=magic(4)

    c =

    16 2 3 13

    5 11 10 8

    9 7 6 12

    4 14 15 1

    K>> max(c) 等同于max(c,[],1)

    ans =

    16 14 15 13

    K>> max(c,[],2)

    ans =

    16

    11

    12

    15

    K>> [m,n]=max(c,[],2)

    m =

    16

    11

    12

    15

    n =

    1

    2

    4

    3

    find; sparse;full

    [i,j,s] = find(S);
    [m,n] = size(S);
    S = sparse(i,j,s,m,n);

    对于稀疏矩阵,i,j分别是不为零项的index,s是其值


    So does this, if the last row and column have nonzero entries:

    [i,j,s] = find(S);
    S = sparse(i,j,s);

     

     

  • 相关阅读:
    BZOJ 3924 / Luogu P3345 [ZJOI2015]幻想乡战略游戏 (动态点分治/点分树)
    BZOJ 3065 带插入区间K小值 (替罪羊树套线段树)
    BZOJ 3217: ALOEXT (块状链表套trie)
    BZOJ 3514: Codechef MARCH14 GERALD07加强版 (LCT维护最大生成树+主席树)
    BZOJ 3932: [CQOI2015]任务查询系统 (主席树板题)
    BZOJ 3658: Jabberwocky (双向链表+BIT)
    BZOJ 1180 [CROATIAN 2009]OTOCI // BZOJ 2843 极地旅行社 // Luogu P4321 [COCI 2009] OTOCI / 极地旅行社 (LCA板题)
    BZOJ 2759 一个动态树好题 (LCT)
    BZOJ 2244: [SDOI2011]拦截导弹 (CDQ分治 三维偏序 DP)
    codefroces 612E Square Root of Permutation
  • 原文地址:https://www.cnblogs.com/huashiyiqike/p/3291078.html
Copyright © 2011-2022 走看看