フィルターのクリア

How to create this specified matrix?

1 回表示 (過去 30 日間)
jack star
jack star 2016 年 5 月 21 日
編集済み: Stephen23 2016 年 5 月 21 日
Hi all. I have some values from U(1)...to...U(500) , and I need help to create this matrix:

採用された回答

Stephen23
Stephen23 2016 年 5 月 21 日
編集済み: Stephen23 2016 年 5 月 21 日
One fast and easy way is to use toeplitz, it only needs one line of code:
>> U = 1:9;
>> toeplitz(U,[U(1),zeros(1,numel(U)-1)])
ans =
1 0 0 0 0 0 0 0 0
2 1 0 0 0 0 0 0 0
3 2 1 0 0 0 0 0 0
4 3 2 1 0 0 0 0 0
5 4 3 2 1 0 0 0 0
6 5 4 3 2 1 0 0 0
7 6 5 4 3 2 1 0 0
8 7 6 5 4 3 2 1 0
9 8 7 6 5 4 3 2 1
or
tril(toeplitz(U))

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 21 日
u=1:10
n=numel(u)
v=repmat(u',1,n)
w=cell2mat(arrayfun(@(x) circshift(v(:,x),[x-1 0]),1:n,'un',0) )
out=tril(w)

Andrei Bobrov
Andrei Bobrov 2016 年 5 月 21 日
tril(toeplitz(u))

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by