transform a vector to a cell array
1 次查看(过去 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.
0 个评论
回答(2 个)
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
2013-12-30
What do you mean? The result is exactly what you asked for. to see the result type
celldisp(out)
Andrei Bobrov
2013-12-29
d = num2cell(c(hankel(1:3,3:numel(c))),2)
3 个评论
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 !
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Encryption / Cryptography 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!