coefficient of a matrix on matlab

4 vues (au cours des 30 derniers jours)
AMAL targhi
AMAL targhi le 1 Juin 2016
Hello assuming we have four matrices
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [9 10; November 12];
D = [13 14; 15 16];
and we want to obtain a new matrix M
M = [[1 5 9 13] [2 6 10, 14]; [3 7 10, 14] [4 8 12 16]]
such as: each field (matrix image) iwritten as [a b c d]
That means :
M (i, j) = printf ("["% d% d% d% d ']', A (i, j), B (i, j), C (i, j), D (i, j ))
I know it is a false writing in matlab but is there such a focntion on matlab with what I write M (i, j) = printf or disp
  5 commentaires
AMAL targhi
AMAL targhi le 1 Juin 2016
Jhon D'Errico sorry there i just a mistake i mean {9 10 11 11 ]
AMAL targhi
AMAL targhi le 1 Juin 2016
[9 10 11 12 ]

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 1 Juin 2016
M = cat(3, A, B, C, D);
  3 commentaires
Walter Roberson
Walter Roberson le 1 Juin 2016
M = reshape(mat2cell([A(:),B(:),C(:),D(:)], ones(1,numel(A)), 4), size(A,1), size(A,2));
If you increased the number of variables you were putting together, you would need to increase the 4 to match.
AMAL targhi
AMAL targhi le 1 Juin 2016
thank you :)

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 1 Juin 2016
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [A(:) B(:)]
Note that MATLAB is column-major, so the first column of C is not [1; 2; 3; 4] but [1; 3; 2; 4]. If you want the former, transpose A before constructing C.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by