フィルターのクリア

Help for a function which works like triu function in matlab

3 ビュー (過去 30 日間)
Anastasia Kyriakou
Anastasia Kyriakou 2020 年 3 月 1 日
回答済み: Sai Sri Pathuri 2020 年 3 月 4 日
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?
  3 件のコメント
Anastasia Kyriakou
Anastasia Kyriakou 2020 年 3 月 1 日
clc
clear all
close all
function U = myTriu(A,k)
for i=1:10
for j=1:10
if (i==1|| j==1 || i=10|| j=10
fprintf('i');
else fprintd('j');
end
end
end
I have written this but it does not seem to be correct
Anastasia Kyriakou
Anastasia Kyriakou 2020 年 3 月 1 日
clear all
close all
function U = myTriu(A,k)
for (i=0 ; i<row; i++
{
for (j=0; j<col ;j++)
{
if (i>j)
{
matrix[i][j]=0;
}
count << matrix[i][j] << '' '' ;
}
count << end1
}
}

サインインしてコメントする。

回答 (1 件)

Sai Sri Pathuri
Sai Sri Pathuri 2020 年 3 月 4 日
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;
end
end
end
U = A;
end

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by