How can I get the upper triangular matrix without using triu()?
50 ビュー (過去 30 日間)
古いコメントを表示
I was able to get the lower triangular matrix by using A(:, 1:end-1), A being my function + argumented matrix but I need to get the upper triangular matrix.
The matrix is Aug= a matrix 3x3, b= 1x3. (A = [Aug b])
3 件のコメント
Voss
2022 年 2 月 27 日
@Jessica Avellaneda Please see my answer, which does not use triu() except to show that the result is correct, which is a part you can omit.
回答 (1 件)
Voss
2022 年 2 月 25 日
編集済み: Voss
2022 年 2 月 27 日
You can set all elements below the main diagonal to zero, e.g., using a for loop:
% A matrix, pick any size you want:
A = randn(5,6);
disp(A);
% zero out the elements below the diagonal to make it upper-triangular:
A_ut = A;
for ii = 1:size(A,2)
A_ut(ii+1:end,ii) = 0;
end
disp(A_ut);
% make sure this gives the same result as triu(A):
isequal(A_ut,triu(A))
0 件のコメント
参考
カテゴリ
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!