transform a vector to a cell array

조회 수: 2 (최근 30일)
allnab
allnab 2013년 12월 29일
댓글: allnab 2013년 12월 30일
Hi,
c=[5 7 1 9 10]; I want to create a cell from this vector as:
d={[5 7 1] [7 1 9] [1 9 10]};
Thanks in advance.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 29일
편집: Azzi Abdelmalek 2013년 12월 29일
c=[5 7 1 9 10];
m=3;
out=arrayfun(@(x) c(x:x+m-1),1:numel(c)-m+1,'un',0)
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 30일
What do you mean? The result is exactly what you asked for. to see the result type
celldisp(out)
allnab
allnab 2013년 12월 30일
Excuse me it works correctly now
thank you

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


Andrei Bobrov
Andrei Bobrov 2013년 12월 29일
d = num2cell(c(hankel(1:3,3:numel(c))),2)
  댓글 수: 3
Jos (10584)
Jos (10584) 2013년 12월 30일
This error is shown when the second input to hanker is empty:
hankel(1:3,[])
In the code above this occurs because,
  • 3:numel(c) is empty, because,
  • numel(c) is less then 3, so,
check the contents of c !
allnab
allnab 2013년 12월 30일
Excuse me it works correctly now
thank you

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

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by