필터 지우기
필터 지우기

Creating a non-square diagonal matrix

조회 수: 20 (최근 30일)
Nikan Fakhari
Nikan Fakhari 2020년 12월 17일
댓글: Nikan Fakhari 2020년 12월 17일
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
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일
B = diag(A(:));
B(94037,1) = 0;

Jan
Jan 2020년 12월 17일
편집: Jan 2020년 12월 17일
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

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by