Creating a non-square diagonal matrix

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 件のコメント

James Tursa
James Tursa 2020 年 12 月 17 日
What is the rule for creating a 94x37x2240 array from a 2240 element vector?
Nikan Fakhari
Nikan Fakhari 2020 年 12 月 17 日
its actaully 94,037 not 94 X 37, so the size im trying to make is a (94,037,2240) matrix
Nikan Fakhari
Nikan Fakhari 2020 年 12 月 17 日
so the real question is that is there a way to make a non-zero diagonal matrix with a desired dimension in matlab?
Nikan Fakhari
Nikan Fakhari 2020 年 12 月 17 日
sorry non-square I meant
James Tursa
James Tursa 2020 年 12 月 17 日
OK, 94037x2240. But what is the rule?

サインインしてコメントする。

回答 (2 件)

Bruno Luong
Bruno Luong 2020 年 12 月 17 日

1 投票

B = diag(A(:));
B(94037,1) = 0;
Jan
Jan 2020 年 12 月 17 日
編集済み: Jan 2020 年 12 月 17 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2020 年 12 月 17 日

コメント済み:

2020 年 12 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by