Help for a function which works like triu function in matlab
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Beantwortet: Sai Sri Pathuri am 4 Mär. 2020
we have seen the function triu(A,k) which extracts upper triangular part of A. But i have to write my own function with the header U = myTriu(A,k) which does the same thing and apply it with A= (2 5 6 4 8 9 10 15 12),k) where k=-2,-1,1
Could anyone help me,please?
Sai Sri Pathuri am 4 Mär. 2020
I think the first code you posted is not relevant to this question and the second code is written in C++ for k = 0 case.
You may use the following code which has a slight modification (checking for i + k > j) for all values of k
function U = myTriu(A,k)
for i = 1: size(A,1)
for j = 1:size(A,2)
if i + k > j
A(i,j) = 0;
U = A;
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!