Filter löschen
Filter löschen

Create parametric block diagonal matrix

2 Ansichten (letzte 30 Tage)
Mehdi Ghasem Moghadam
Mehdi Ghasem Moghadam am 15 Feb. 2017
Kommentiert: Star Strider am 15 Feb. 2017
how can create parametric block diagonal matrix in Matlab
for i=1:2
H = blkdiag(sym('H%d',num2str(i),[1 1]));
end

Antworten (1)

Star Strider
Star Strider am 15 Feb. 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 Kommentare
Mehdi Ghasem Moghadam
Mehdi Ghasem Moghadam am 15 Feb. 2017
Thanks, but I need Block Diagonal matrix like: H = [ H1, 0] [ 0, H2] [ 0, H3]
Star Strider
Star Strider am 15 Feb. 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]

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by