Splitting up and N size array into parts

3 次查看(过去 30 天)
I basically have a number of matrixes (N,1) that i want to split up into smaller arrays. I want to split them into say 10 pieces irrelevant of the number of components. I tried using reshape but that has issues with prime numbers
How can i split an N length array into 10 other pieces and store as a cell?

采纳的回答

Thorsten
Thorsten 2016-8-3
N = 613;
P = 10;
X = rand(N, 1);
r = diff(fix(linspace(0, N, P+1)))
C = mat2cell(X, r, 1)

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-3
Use matcell, look at this example
N=randi(100,100,1)
B=mat2cell(N,10*ones(10,1),1)
  3 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2016-8-3
N=randi(100,613,1)
n=numel(N)
m=fix(n/100)
p=mod(n,100)
B=[mat2cell(N(1:m*100),100*ones(m,1),1);{N(100*m+1:100*m+p)}]
Matthew
Matthew 2016-8-3
Ok thanks Ill have a look.. I found a way to do it also by just inserting a row of zeros and replacing the appropriate rows..Yours looks more simple though =]

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by