Effacer les filtres
Effacer les filtres

Create parametric block diagonal matrix

2 vues (au cours des 30 derniers jours)
Mehdi Ghasem Moghadam
Mehdi Ghasem Moghadam le 15 Fév 2017
Commenté : Star Strider le 15 Fév 2017
how can create parametric block diagonal matrix in Matlab
for i=1:2
H = blkdiag(sym('H%d',num2str(i),[1 1]));
end

Réponses (1)

Star Strider
Star Strider le 15 Fév 2017
See if this does what you want:
h = sym('H%d',[1 2]); % Create Vector
h = mat2cell(h, 1, [1 1]); % Convert Vector To Cell Array Of Individual Elements (Comma-Separated List)
H = blkdiag(h{:}) % Desired Result
H =
[ H1, 0]
[ 0, H2]
The blkdiag function wants a comma-separated list, and a cell array provides that. This code creates your initial vector (as I believe you want it), then converts it to a cell array, then uses it to create your block-diagonal matrix.
If this is not the result you want, please describe in detail what you want your desired result to be.
  2 commentaires
Mehdi Ghasem Moghadam
Mehdi Ghasem Moghadam le 15 Fév 2017
Thanks, but I need Block Diagonal matrix like: H = [ H1, 0] [ 0, H2] [ 0, H3]
Star Strider
Star Strider le 15 Fév 2017
This seems to do what you want:
h = sym('H%d',[1 3]); % Create Vector
h = mat2cell(h, 1, [1 2]); % Convert To Cell Array
H = blkdiag(h{:}).' % Desired Result (Simple — Not Complex Conjugate — Transpose)
H =
[ H1, 0]
[ 0, H2]
[ 0, H3]

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by