divide a vector in subvectors
9 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a long vector, and I want to divide it for example in subvectors of size 100. without using a reshape() because I don't know the size of my long vector and so it doesn't fit perfectly in a M*N matrix. So, how can I do it? thank you
1 件のコメント
回答 (2 件)
Andrei Bobrov
2016 年 5 月 10 日
編集済み: Andrei Bobrov
2016 年 5 月 10 日
A = randi(12,27,1); % - your vector
M = 4;
out = reshape([A;nan(mod(-numel(A),M),1)],M,[]);
0 件のコメント
Guillaume
2016 年 5 月 10 日
v = rand(1, 1024); %demo data. length is not a multiple of 100
splitlength = 100;
sublengths = ones(1, ceil(numel(v)/splitlength)) * splitlength;
sublengths(end) = sublengths(end) + numel(v) - sum(sublengths); %adjust length of last block
subvectors = mat2cell(v, 1, sublengths)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!