MATLAB: Preallocation of matrix with undetermined dimensions.

odometerpreallocationunknown dimensions

I need to generate a matrix with a number of dimensions which will be determined by user inputs.
So zeros(3,3,3) gives me a 3x3x3 matrix. My problem is that I need zeros(3,3,3,…..,3) where there are N number of dimensions all of size 3. N is determined by user inputs. Is there a way to efficiently accomplish this, or am I stuck creating a matrix of large dimensions and just under filling it?
Final note: as it is a user-input determined value, I'd really like to avoid using eval() if possible.
Thank you for any assistance you can offer!

Best Answer

zeros(3 * ones(1,N))