zoukankan      html  css  js  c++  java
  • matlab矩阵中每一行数除以一个数

    例如:用a中每一行数除以x中相对应的每一个数

    x=[5 10 6 8 16 6 8 8 22 11];
    a=[4 4 4 5 4 4 4 4 3 4
    6 8 6 2 6 8 8 6 8 6
    4 4 4 4 6 4 4 4 6 4
    4 6 6 4 6 6 6 4 7 4
    10 14 14 10 12 12 12 10 14 12
    3 5 5 3 6 3 3 4 5 4
    4 6 7 4 4 4 4 4 6 6
    4 6 6 6 5 6 5 5 7 6
    13 16 19 16 13 13 10 13 16 13
    8 9 10 8 8 7 8 8 9 8
    ];

     

    %a的第i行除以x的第i个数
    xa=repmat(x',[1 10]);
    a=a./xa;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    函数repmat用法

    B =repmat(A,m,n)
    B = repmat(A,[mn])
    B = repmat(A,[m np...])

    这是一个处理大矩阵且内容有重复时使用,其功能是以A的内容堆叠在(MxN)的矩阵B中,B矩阵的大小由MxNA矩阵的内容决定,如果A是一个3x4x5的矩阵,有B = repmat(A,2,3)则最后的矩阵是6x12x5

    例如:

    B = [1 2 3;4 5 6;7 8 9]

    B(:,1)      % 
    B矩阵的第1

    repmat(B(:,1),1,5)      % 
    B(:,1) 复制成'1×5'的矩阵
    运算结果:

    ans =

         1     1    1     1     1

         4     4    4     4     4

         7     7    7     7     7
    repmat(B(:,1),2,5)      % 
    B(:,1) 复制成'2×5'的矩阵

    ans =

         1     1    1     1     1

         4     4    4     4     4

         7     7    7     7     7

         1     1    1     1     1

         4     4    4     4     4

         7     7    7     7     7

    其结果变为6*5A也可以置放文字串,如:
    >>C=repmat(' Long live the king!', 2,2)

    运算结果:
    C =
    Long live the king! Long live the king!
    Long live the king! Long live the king!

    也可置放其他的:
    >> D=repmat(NaN,2,5)

    运算结果:
    D =
    NaN   NaN   NaN   NaN   NaN
    NaN   NaN   NaN   NaN   NaN


  • 相关阅读:
    iOS开发基础知识--碎片7
    python---ORM之SQLAlchemy(3)外键与relationship的关系
    python---ORM之SQLAlchemy(2)外键使用
    python---ORM之SQLAlchemy(1)
    python---自定义字段验证
    mysql -- 慢日志使用
    mysql -- 索引补充
    mysql -- 动态获取结果集(重点)
    mysql -- 逻辑语句
    mysql -- 事务
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3061815.html
Copyright © 2011-2022 走看看