Find minimum among matrices with different sizes

1 回表示 (過去 30 日間)
Gaetano Pavone
Gaetano Pavone 2023 年 3 月 22 日
編集済み: Dyuman Joshi 2023 年 3 月 22 日
Hello,
I have two matrices: A=[2 8 4; 7 3 9] and B=[1 3 5]. I want to compare A and B for finding the minimum values such that the first row of A will be compared with the first row of B. Moreover, the rows of A exceeding the size of B will be not compared.
Thus, the comparison should generate a matrix C with the same sizes of A, that is: C=[1 3 4;7 3 9].
Thanks,
Best

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 3 月 22 日
Your statements contradict each other, but I guess this is what you want to obtain
A=[2 8 4; 7 3 9];
B=[1 3 5];
C=min(A,B)
C = 2×3
1 3 4 1 3 5
  2 件のコメント
Gaetano Pavone
Gaetano Pavone 2023 年 3 月 22 日
I've edited my question
Dyuman Joshi
Dyuman Joshi 2023 年 3 月 22 日
編集済み: Dyuman Joshi 2023 年 3 月 22 日
A=[2 8 4; 7 3 9];
B=[1 3 5];
%method 1
%comparing and then adding the remaining rows of A
C1=[min(A(1,:),B);A(2,:)]
C1 = 2×3
1 3 4 7 3 9
%method 2
%assinging and then comparing
C2=A;
C2(1,:)=min(C2(1,:),B)
C2 = 2×3
1 3 4 7 3 9
%method 3
%modifying B and then comparing
B1=[B;Inf*B];
C3=min(A,B1)
C3 = 2×3
1 3 4 7 3 9

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by