Repeat matrix element of a given matrix

1 回表示 (過去 30 日間)
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 11 日
コメント済み: Andrei Bobrov 2015 年 3 月 13 日
my matrix is x=[2 5 3 6 1]
I want it to make it as y=[2 2 2 2 5 5 5 5 3 3 3 3 6 6 6 6 1 1 1 1]
which function does it?
  1 件のコメント
Jan
Jan 2015 年 3 月 11 日
This topic is discussed such frequently, that I miss it in the FAQ.

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

採用された回答

Jan
Jan 2015 年 3 月 11 日
編集済み: Jan 2015 年 3 月 11 日
x = [2 5 3 6 1];
y = reshape(repmat(x, 4, 1), 1, []);
Or:
y = kron(x, ones(1, 4));
  3 件のコメント
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 13 日
Hi Jan Simon can you help me to regain x from y. I have used kron in my coding.
Guillaume
Guillaume 2015 年 3 月 13 日
That would be
x = y(1:4:end);
This is basic matrix indexing.
In the future, start a new question rather than asking in comments.

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

その他の回答 (3 件)

Stephen23
Stephen23 2015 年 3 月 11 日
編集済み: Stephen23 2015 年 3 月 11 日
Another quick one-liner:
reshape(ones(4,1)*x,1,[])
  2 件のコメント
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 11 日
Thank you Stephen Cobeldick
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 13 日
Hi Stephen Cobeldick can you help me to regain original matrix

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


Guillaume
Guillaume 2015 年 3 月 11 日
New in 2015a, repelem:
repelem(x, 4)
  1 件のコメント
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 11 日
thank you Guillaume.

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


Andrei Bobrov
Andrei Bobrov 2015 年 3 月 11 日
x = [2 5 3 6 1];
y = x(ceil((1:4*numel(x))/4));
  3 件のコメント
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 13 日
Hi Andrei Bobrov can you help me to regain x from y
Andrei Bobrov
Andrei Bobrov 2015 年 3 月 13 日
x = unique(y);

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by