0
votes

I have two matrices with the following dimensions:

A = [61X50] 
B = [61X39]

I need to find the minimum value between each corresponding cell between these two matrices and put them in an array C. If there is a missing value (since A has 50 columns and B has 39) - the value from array A should be taken into consideration.

What would be the best way to achieve this in MATLAB ?

Edit:

Here's an example

Say A = [3 X 3] = [ 1 1 1; 2 2 2; 3 3 3] and B = [3 X 2] = [ 0 0; 0 1; 1 2]

Array C should hold: [ 0 0 1; 0 1 2; 1 2 3] (Comparing each value in A and B column wise)

1
Create a small example with sample matrices. - Sardar Usama
Updated with example - 221b

1 Answers

2
votes

You can just preallocate C with the values of A and so the values that are missing in B will automatically be the values of A. Then you can use the min-function of matlab to find the minima that ou are looking for. It would look like this:

C=A;
C(:,1:size(B,2))=min(A(:,1:size(B,2)),B)