フィルターのクリア

Need to combine two matrix

1 回表示 (過去 30 日間)
Santhosh Chandrasekar
Santhosh Chandrasekar 2018 年 4 月 23 日
コメント済み: Akira Agata 2018 年 4 月 25 日
Hi, I have two matrices P= 1 2;3 4;5 6; Q= 7 8;9 10;11 12;
I want the result
R=
{[1 7] [2 8];
[3 9] [4 10];
[5 11] [6 12]};
Can any one help me?

採用された回答

Akira Agata
Akira Agata 2018 年 4 月 23 日
How about the following?
R = mat2cell([P(:) Q(:)],ones(1,numel(P)))
R = reshape(R,[],2);
  2 件のコメント
Santhosh Chandrasekar
Santhosh Chandrasekar 2018 年 4 月 23 日
編集済み: Santhosh Chandrasekar 2018 年 4 月 23 日

Thank you very much!

 but I am getting this error while using a function.
"Conversion to double from cell is not possible"

My requirement is to use that in the below-mentioned function

in_mat={[4 1] [0 0]; [0 0] [1 4]};

%[solve,A,B]= GTbimatrixgames(in_mat, 1)

Akira Agata
Akira Agata 2018 年 4 月 25 日

Seems strange. Please try the following. In my MATLAB R2018a, it works without any warning/error.

P= [1 2;3 4;5 6];
Q= [7 8;9 10;11 12];
R = mat2cell([P(:) Q(:)],ones(1,numel(P)));
R = reshape(R,[],2);

Regarding your second comment, the required function would be like this (assuming in_mat is N-by-4 cell array and each element is 1-by-2 numeric vector).

function [A,B] = GTbimatrixgames(in_mat)
C = cell2mat(in_mat);
A = C(:,[1 3]);
B = C(:,[2 4]);
end

By the way, could you tell me what is the second input argument '1' and first output argument 'solve' of the required function described in your comment?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by