I have two matrices: A & B ... I want to combine them so that every element will be near the other one's corresponding element. For example something like C matrix.
A=[1,2;3,4]
B=[5,6;7,8]
C=[15,26; 37, 48]

3 件のコメント

Mohammad Sami
Mohammad Sami 2020 年 1 月 23 日
編集済み: Mohammad Sami 2020 年 1 月 23 日
Option 1
str2double(strcat(string(A),string(B)))
Option 2
str2double(reshape(compose('%i%i',A(:),B(:)),size(A,1),size(A,2)))
Walter Roberson
Walter Roberson 2020 年 1 月 23 日
Note that if you have negative entries then you will need to define what the results are expected to be.
Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
Mohammad Sami Thank you , these options are great, but they don't work when the second matrix has a negative element

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

 採用された回答

Walter Roberson
Walter Roberson 2020 年 1 月 23 日

1 投票

A*10+B

6 件のコメント

Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
Thank you, but I don't want it to be one number,,, also I do have negative numbers in my actual code, this is just an example. I want them to combine so that each element will stand near the other matrix's corresponding element
Walter Roberson
Walter Roberson 2020 年 1 月 23 日
What does "stand near" mean to you?
Walter Roberson
Walter Roberson 2020 年 1 月 23 日
kron(A, [1 0]) + kron(B, [0 1])
Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
I want them to be separate numbers and be close be the other corresponding one ..for example when
A(1,2)=-2
B(1,2)=-6
then C(1,2)=-2 -6
Walter Roberson
Walter Roberson 2020 年 1 月 23 日
That is not possible in MATLAB unless you are willing to use cell arrays C{1,2} = [-2 -6]
Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
okay ,sorry I didn't see your 'kron(A, [1 0]) + kron(B, [0 1])' answer , I think this is the most convenient one. Thank you !!!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by