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)

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일

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by