フィルターのクリア

how to create increasing number pyramid matrix?

3 ビュー (過去 30 日間)
yonatan s
yonatan s 2019 年 1 月 13 日
コメント済み: yonatan s 2019 年 1 月 14 日
hello,
how do I create a matrix of the form:
1 2 3 4 5
6 7 8 0 0
9 10 0 0 0
11 0 0 0 0
in this example N=5. I need a solution for any N.
EDIT:
I'm performing manual clustering. in this example of five points. points 1&2 have been clustered together to a new point - 6. points 3&4 have been clustered together to a new point - 7. points number 5 was reassigned to point 8, and so on.
thanks
  3 件のコメント
yonatan s
yonatan s 2019 年 1 月 13 日
i've edited the question, hope it is clear now
Rik
Rik 2019 年 1 月 13 日
Or is this the N=6 output?
1 2 3 4 5 6
7 8 9 0 0 0
10 11 0 0 0 0
12 0 0 0 0 0
(halving the number of non-zero elements on each row (rounding up), making each non-zero element a unique value)

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

採用された回答

Rik
Rik 2019 年 1 月 13 日
In case that is the pattern you're looking for, here is the code that implements it:
function M=create_stairs_matrix(N)
M=zeros(N,1);M(1)=N;n=1;%prepare for loop
while M(n)>1
%halve number of elements (rounding up) until 1 is reached
M(n+1)=ceil(M(n)/2);
n=n+1;
end
M((n+1):end)=[];%remove empty rows
nonzeroelems=sum(M);
%mark the number of elements to be filled with a true
M=(1:N)<=M;%implicit expansion (use bsxfun on <R2016b)
M=double(M');
M(logical(M))=1:nonzeroelems;
M=M';
end
  1 件のコメント
yonatan s
yonatan s 2019 年 1 月 14 日
perfect. thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClusters and Clouds についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by