map a matrix with another matrix

后端 未结 2 1455
终归单人心
终归单人心 2021-01-24 11:04

I have a question to the mapping of a matrix with another matrix which contains only 1 and 0. Here an example of my problem: A is the matrix with doubles



        
相关标签:
2条回答
  • 2021-01-24 11:48

    Just multiply A and B element-wise:

    C = A.*B
    
    0 讨论(0)
  • 2021-01-24 11:58

    I like Dan's solution, but this would be another way:

    C = zeros(size(A));
    C(B==1) = A(B==1);
    
    0 讨论(0)
提交回复
热议问题