element wise concatenation of square matrices
Mostra commenti meno recenti
Hi, I have the following two square matrices:
A=
17 24 1
23 65 7
4 6 13
B=
18 27 35
2 5 8
4 16 11
I want to concatenate the elements of matrices A and B to form a cell C such that:
C= <17,18> <24,27> <1,35>
<23,2> <65,5> <7,8>
<4,4> <6,16> <13,11>
Please help. (I want to avoid using for loop)
Risposte (4)
Azzi Abdelmalek
il 12 Feb 2013
Modificato: Azzi Abdelmalek
il 12 Feb 2013
n=numel(A)
out=arrayfun(@(x) [A(x) B(x)],1:n,'un',0)
5 Commenti
Azzi Abdelmalek
il 12 Feb 2013
Modificato: Azzi Abdelmalek
il 12 Feb 2013
What do you mean: as a string? '1718'? or what?
Azzi Abdelmalek
il 12 Feb 2013
Modificato: Azzi Abdelmalek
il 12 Feb 2013
out=arrayfun(@(x) num2str([A(x) B(x)]),1:n,'un',0)
Azzi Abdelmalek
il 12 Feb 2013
Ok, what about
out=arrayfun(@(x,y) num2str([x y]),A,B,'un',0)
Like this?
C = arrayfun(@(x) ['<' num2str(A(x)) ',' num2str(B(x)) '>'], 1:numel(A), 'un', 0);
C = reshape(C, [3 3]);
Sean de Wolski
il 12 Feb 2013
cellfun(@squeeze,num2cell(cat(3,A,B),3),'Uni',false)
zozo
il 12 Feb 2013
2 Commenti
Azzi Abdelmalek
il 12 Feb 2013
out=arrayfun(@(x,y) num2str([x y]),A,B,'un',0)
zozo
il 12 Feb 2013
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!