MATLAB Answers

Combining two separate arrays into singular payoff matrix

33 ビュー (過去 30 日間)
Olivia Simuoli
Olivia Simuoli 2020 年 9 月 22 日 22:08
コメント済み: madhan ravi 2020 年 9 月 23 日 7:25
Hi everyone,
I have two separate arrays that I am hoping to combine into a singular payoff matrix. Does anyone have any tips for doing so?
Right now, I have two 2x2 arrays that look like:
A = [4 2,
2 0]
B = [4 2,
4 2]
Instead of having them be separate, I want to combine them into a singular 2x2 payoff matrix P with the end result looking like:
P = [(4,4) (2,2),
(2,4) (0,2)]
I want to avoid manually typing in cell values and am looking for some way to achieve the end result by combining the existing A and B arrays. I would appreciate any help. Thank you!

  0 件のコメント

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

採用された回答

madhan ravi
madhan ravi 2020 年 9 月 22 日 22:17
P = reshape(num2cell([A(:), B(:)], 2), [], size(A, 2));
celldisp(P)

  2 件のコメント

Olivia Simuoli
Olivia Simuoli 2020 年 9 月 23 日 0:03
Thanks, that worked! Is there some way to see the full array without out having to view each cell individually? I am new to MATLAB so I don't even know if that's possible.
madhan ravi
madhan ravi 2020 年 9 月 23 日 7:25
P{ : }

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

その他の回答 (1 件)

Mario Malic
Mario Malic 2020 年 9 月 22 日 22:23
編集済み: Mario Malic 2020 年 9 月 22 日 22:25
I could suggest this
C = cat(3, A, B)
>> C
C(:,:,1) =
4 2
2 0
C(:,:,2) =
4 2
4 2
% If you're looking for summing A(1,1) + B(1,1), you can try this
>> sum(C,3)
ans =
8 4
6 2

  3 件のコメント

madhan ravi
madhan ravi 2020 年 9 月 22 日 22:26
Why not A + B ?
Mario Malic
Mario Malic 2020 年 9 月 22 日 22:31
Ah true xD, but it was just an example, maybe summing over other dimensions makes more sense for such approach.
Olivia Simuoli
Olivia Simuoli 2020 年 9 月 23 日 0:03
Thanks, that worked as well!

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by