Dear all,
here is a cell matrix
k={
12 'kol'
23 'Sew'
45 'awe'
44 'wow'
}
I would like to replicate each element twice so as to have
k={
12 'kol'
12 'kol'
23 'Sew'
23 'Sew'
45 'awe'
45 'awe'
44 'wow'
44 'wow'
}
I was thinking something like
cr=cellfun(@(x) repmat(x,2,1),k,'uni',false);
but I do not know if I am correct. Is there any better code?
Would there any difference if I had
k={
'12' 'kol'
'23' 'Sew'
'45' 'awe'
'44' 'wow'
}
thanks

 채택된 답변

the cyclist
the cyclist 2012년 7월 26일

0 개 추천

Here's one way:
nk = size(k,1);
idx = [1:nk;1:nk];
k(idx(:),:)

댓글 수: 2

Sabbas
Sabbas 2012년 7월 26일
편집: Sabbas 2012년 7월 26일
if I wanted to replicate each element of the above matrix 1000 times instead of 2 how could I modify your code?
thanks
Use
idx = repmat(1:nk,[1000 1]);
in place of the second line.

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

추가 답변 (1개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2012년 7월 26일

답변:

2018년 9월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by