[英]Find minimum value between each cell between two matrices in matlab
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. 我需要找到这两个矩阵之间的每个对应单元格之间的最小值,并将它们放入数组C中。如果存在缺失值(因为A具有50列,而B具有39列)-应该将数组A中的值计入考虑。
What would be the best way to achieve this in MATLAB ? 在MATLAB中实现此目标的最佳方法是什么?
Edit: 编辑:
Here's an example 这是一个例子
Say A = [3 X 3] = [ 1 1 1; 2 2 2; 3 3 3]
假设A = [3 X 3] = [ 1 1 1; 2 2 2; 3 3 3]
A = [3 X 3] = [ 1 1 1; 2 2 2; 3 3 3]
A = [3 X 3] = [ 1 1 1; 2 2 2; 3 3 3]
and B = [3 X 2] = [ 0 0; 0 1; 1 2]
A = [3 X 3] = [ 1 1 1; 2 2 2; 3 3 3]
, B = [3 X 2] = [ 0 0; 0 1; 1 2]
B = [3 X 2] = [ 0 0; 0 1; 1 2]
Array C should hold: [ 0 0 1; 0 1 2; 1 2 3]
数组C应该保持: [ 0 0 1; 0 1 2; 1 2 3]
[ 0 0 1; 0 1 2; 1 2 3]
[ 0 0 1; 0 1 2; 1 2 3]
(Comparing each value in A and B column wise) [ 0 0 1; 0 1 2; 1 2 3]
(将A和B列中的每个值进行比较)
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
. 您只需为C
分配A
的值即可,因此B
中缺少的值将自动成为A
的值。 Then you can use the min
-function of matlab to find the minima that ou are looking for. 然后,您可以使用matlab的min
函数找到您正在寻找的最小值。 It would look like this: 它看起来像这样:
C=A;
C(:,1:size(B,2))=min(A(:,1:size(B,2)),B)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.