how to put output of a function in diagonal of matrix
조회 수: 6 (최근 30일)
이전 댓글 표시
how would i have a function output become the diagonal of a matrix, for instance
function y=f(x)
y= 3x+1;
end
how do i put the output of this function as the diagonal of a matrix with 0s everywhere else. i've attempted some type of for loop but it doesnt seem to work
i.e. the diagonal should have y(0), y(1), y(2),... y(n),
for different values of n
댓글 수: 0
채택된 답변
James Tursa
2016년 7월 29일
편집: James Tursa
2016년 7월 29일
If y is a vector, then simply
y = diag(y);
If y is a matrix and you are trying to pick off the diagonal, then e.g.,
y = diag(diag(y));
댓글 수: 2
Stephen23
2016년 7월 31일
@akay: y is not a function, f if your function. The answer you have given puts y into the diagonal of a matrix. If this is not what you want please explain in more detail.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!