i have
x = [8, 9, -3, 9, 5, -4, -1, 3, 10, 10]
y = [-6; 4; 4; -2; 2]
z = diag(y)
how can i reconstruct matrix z into this look?
z =
-6 0 0 0 0 8
0 4 0 0 0 9
0 0 4 0 0 -3
0 0 0 -2 0 9
0 0 0 0 2 5
8 9 -3 9 5 -4
is there other way than this?
z = [-6 0 0 0 0 8; 0 4 0 0 0 9; 0 0 4 0 0 -3; 0 0 0 -2 0 9; 0 0 0 0 2 5; 8 9 -3 9 5 -4]

댓글 수: 1

Rik
Rik 2021년 5월 13일
Where are the lower values coming from? Do you just want to put the values of x on the lower and right edges?
What have you tried to put them there?

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 13일

1 개 추천

x = [8, 9, -3, 9, 5, -4, -1, 3, 10, 10];
y = [-6; 4; 4; -2; 2];
z = [diag(y), x(1:5).'; x(1:6)]
z = 6×6
-6 0 0 0 0 8 0 4 0 0 0 9 0 0 4 0 0 -3 0 0 0 -2 0 9 0 0 0 0 2 5 8 9 -3 9 5 -4

댓글 수: 2

Hearthy Tampol
Hearthy Tampol 2021년 5월 13일
thanks! didn't know there are other ways.
may I also ask how could I change its elements in a certain row for particular numbers?
example, i am planning to change the 4th row of matrix z with the with the last 6 elements of vector a?
z(4,:) = a(end-5:end);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Hill
David Hill 2021년 5월 13일

1 개 추천

z=diag([y;0]);
z(end,:)=x(1:length(z));
z(:,end)=x(1:length(z));

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품

릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by