function [ndim,mdim]=fixdim(n,m) % make sure vector n is length at least m by adding 1s if necessary % to counter the unfortunate effect of size on multidimensional arrays % also make sure mdim is at least 2 ln=length(n); if ln>m, if any(n(m+1:ln)~=1), error('too many dimensions') end end if m==1, mdim=2; else mdim=m; end ndim=[n,ones(1,mdim-ln)];