フィルターのクリア

Creating a matrix having repeating elements

2 ビュー (過去 30 日間)
Rengin
Rengin 2019 年 9 月 4 日
コメント済み: Rengin 2019 年 9 月 4 日
% Dear users,
% Assume that I have a A matrix having the size of 5x5 and in the end;
% I want to get A=[1 -1 0 0 0; 1 -1 0 0 0; 0 1 -1 0 0; 0 1 -1 0 0; 0 0 1 -1 0]
% What is the easiest way to do it?
% Thanks in advance
  6 件のコメント
Bruno Luong
Bruno Luong 2019 年 9 月 4 日
OK here is different and still simple:
A=[1 -1 0 0 0; 1 -1 0 0 0; 0 1 -1 0 0; 0 1 -1 0 0; 0 0 1 -1 0]+0
The point is your question is not well formulated
Rengin
Rengin 2019 年 9 月 4 日
Thanks but I was still be able to get my answer. It works perfectly fine.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 9 月 4 日
編集済み: Andrei Bobrov 2019 年 9 月 4 日
A = kron(eye(5),[1;1])+kron(diag(-ones(4,1),1),[1;1]);
out = A(1:5,:);
or
n = 1:5;
A = repmat([1,-1,0,0,0],5,1);
out = A(mod(repmat(n,5,1) - ceil(n(:)/2),5)*5 + n(:));
  2 件のコメント
madhan ravi
madhan ravi 2019 年 9 月 4 日
You always impress without a doubt , a +1 from me.
Andrei Bobrov
Andrei Bobrov 2019 年 9 月 4 日
Thank you Madhan!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by