If you understood correctly, assuming that your matrix is โโdenoted by m , this is what you wanted:
a=num2cell(reshape(m(:,1:size(m,2)-mod(size(m,2),L)),N*L,[]),1); a=cellfun(@(n) reshape(n,N,L), a,'UniformOutput',false); a{end+1}=m(:,end-mod(size(m,2),L)+1:end);
(this can be shortened to one line if you want) ... Let's check a few minimum numbers:
m=rand(50,334); N=50; L=100;
gives:
a = [50x100 double] [50x100 double] [50x100 double] [50x34 double]
Note that I did not check the exact size in the change, so you may need to change the shape to ...,[],N*L) , etc.
source share