Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add Singleton dimensions

889 views
Skip to first unread message

Matt

unread,
Oct 6, 2010, 5:28:03 AM10/6/10
to
Hi there,

Does anyone know how to add singleton dimensions to an array?

I currently have a matrix A that is size 1010025x1. I would like to add a 3rd dimension to this so that it's 1010025x1x1. I've tried permute(A, [1 2 3]) however this doesn't work giving me the dimensions I had at the start again ( 1010025x1)...

Cheers!
Matt

Malcolm Lidierth

unread,
Oct 6, 2010, 5:50:05 AM10/6/10
to
Only on disc using AddDimension in the MAT-file utilities on the FEX. My notes for those say:

....AddDimension adds the dimension to the data on disc. Most MATLAB functions including LOAD, WHOS etc strip away any trailing singleton dimensions so the effects of AddDimension will not show until the final dimension is >=2.

Loren Shure

unread,
Oct 6, 2010, 8:10:38 AM10/6/10
to

"Matt " <matthew...@gmail.com> wrote in message
news:i8hff3$fn2$1...@fred.mathworks.com...

MATLAB implicitly has an infinite number of trailing singleton dimensions
after the non-singleton array dimensions. If you are trying to fill in the
3rd dimension, you can just do something like this:

A(2:3,1,4) = 17;

The array will then be 1010025x1x4 and values not specified will be filled
with 0. Unless your array is sparse, in which case, they are only 2-d.

--
Loren
http://blogs.mathworks.com/loren/
http://matlabwiki.mathworks.com/MATLAB_FAQ

0 new messages