Creating a non-square diagonal matrix
Show older comments
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 Comments
James Tursa
on 17 Dec 2020
What is the rule for creating a 94x37x2240 array from a 2240 element vector?
Nikan Fakhari
on 17 Dec 2020
Nikan Fakhari
on 17 Dec 2020
Nikan Fakhari
on 17 Dec 2020
James Tursa
on 17 Dec 2020
OK, 94037x2240. But what is the rule?
Answers (2)
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
1 Comment
Nikan Fakhari
on 17 Dec 2020
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!