combining and separating two matrices

3 views (last 30 days)
I have two matrices
A matrix:
1 2 4
7 5 3
9 5 1
B matrix:
3 8 4
5 4 2
8 3 6
I want to combine them like this.
D matrix:
1-3 2-8 4-4
7-5 5-4 3-2
9-8 5-3 1-6
Note : (The - sign I put in is meaningless. It can be different signs or spaces.)
And can I separate these matrices again after writing them in the same cell?
Thank you for help
  2 Comments
Berfin Çetinkaya
Berfin Çetinkaya on 24 Mar 2022
I want it to stay as a string So I want it to stay 1-2.
I don't have deep knowledge in matlab but I need to use it in a project. And where I hang out, what I find on the internet doesn't work for me. So I would be glad if you could help me.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 24 Mar 2022
A = [1 2 4
7 5 3
9 5 1] ;
B =[3 8 4
5 4 2
8 3 6] ;
D = cell(3,3) ;
for i = 1:3
for j = 1:3
D{i,j} = [num2str(A(i,j)),'-',num2str(B(i,j))] ;
end
end
D
D = 3×3 cell array
{'1-3'} {'2-8'} {'4-4'} {'7-5'} {'5-4'} {'3-2'} {'9-8'} {'5-3'} {'1-6'}

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!