Comparing 2 Matrices Element By Element

P
Prisha · Jul 17, 2020 · 1.9K views
Question
I have 2 matrices A and B, both 7x3. I want to compare each element in A with its corresponding element in B, taking the larger of the 2 values and creating a new Matrix C. Could someone suggest a method on how I would do this? I have seen examples of comparing to find equality between 2 elements but not a comparison to create a new matrix so I am finding this rather difficult.
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Aug 26, 2026

Use the max function. Try:

 

A = rand(3);
B = rand(3);
C = max(A,B)
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!