MATLAB: How to create a matrix that includes the elements of other matrices that happen to meet a certain condtion

logical?matrices

Really new at this stuff, trying to do a problem for homework where I am supposed to create two equal size matrices and create a new equally sized matrix where each element is the larger of the corresponding elements of the two original matrices. I need to do the same problem using different loops and also not using loops but I am just really stuck on getting the greater of two corresponding elements and making a new equally sized matrix out of them where each element is in the spot. If (2,4) of matrix one is a bigger number it needs to be (2,4) of the third matrix) .I can create functions that give me the numbers I want but I just can't figure out the rest. Any insight would be appreciated.

Best Answer

  • if A(J,K) > B(J,K)
    C(J,K) = A(J,K);
    else
    C(J,K) = B(J,K);
    end