Creating a non-square diagonal matrix

22 vues (au cours des 30 derniers jours)
Nikan Fakhari
Nikan Fakhari le 17 Déc 2020
Commenté : Nikan Fakhari le 17 Déc 2020
Hi there,
I have a vector A that contains 2240 elements and I wanted to create a non-square diagonal matrix out if (B) that has the following dim: (94,037,2240),
I cant really use the diag function in matlab beause that gives me a square diagonal matrix,
Could you please help me with this issue?
  5 commentaires
Nikan Fakhari
Nikan Fakhari le 17 Déc 2020
sorry non-square I meant
James Tursa
James Tursa le 17 Déc 2020
OK, 94037x2240. But what is the rule?

Connectez-vous pour commenter.

Réponses (2)

Bruno Luong
Bruno Luong le 17 Déc 2020
B = diag(A(:));
B(94037,1) = 0;

Jan
Jan le 17 Déc 2020
Modifié(e) : Jan le 17 Déc 2020
s1 = 94037;
s2 = 2240;
v = rand(1, s2); % Test data
M = zeros(s1, s2);
M(1:s1+1:s1*s2) = v; % Linear indexing
Or if s2 > s1:
s1 = 2;
s2 = 4;
v = rand(1, s1); % Test data
M = zeros(s1, s2);
M(1:s1+1:s1*s1) = v; % Linear indexing

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