How to joint together two matrix?

1 view (last 30 days)
Kenny
Kenny on 25 Feb 2019
Answered: madhan ravi on 25 Feb 2019
I have these two matrix
A = 4 4 4 4 B = 1 2 3 4
3 3 3 3 1 2 3 4
2 2 2 2 1 2 3 4
1 1 1 1 1 2 3 4
I want to get together both, like this
C = 4,1 4,2 4,3 4,4
3,1 3,2 3,3 3,4
2,1 2,2 2,3 2,4
1,1 1,2 1,3 1,4
There is some function for this?

Answers (2)

Kevin Phung
Kevin Phung on 25 Feb 2019
A =[4 4 4 4 ;3 3 3 3;2 2 2 2;1 1 1 1];
B = repmat(1:4,4,1);
C = cell(1,numel(A));
for i = 1:numel(A)
C{i} = [A(i) B(i)];
end

madhan ravi
madhan ravi on 25 Feb 2019
C=reshape(num2cell([A(:) B(:)],2),4,[]);
% celldisp(C)

Community Treasure Hunt

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

Start Hunting!