The role of singleton elements in calls to the zeros function.

2 visualizaciones (últimos 30 días)
Hello MatLab'rs,
I'm confused by the return of zeros under certain circumstances.
For some vector V, calling zeros will create a length(V) dimensional matrix:
>> V = [ 1:10 ]
V =
1 2 3 4 5 6 7 8 9 10
>> Z = zeros(V); % Z = <10-D double>
In my code I have a selectedDimLengths vector, each element of which can change from a singleton up to about 6 or 7, but often looks something like:
selectedDimLengths =
1 1 1 5 5 1 1 1 3 1 1 1 1
>> Z = zeros(selectedDimLengths); % Z = <9-D double>
when I pass this to zeros I lose a couple of dimensions, down to 9 when I expect 13. What role do the singleton elements play here? Why?
Are the trailing singleton elements cropped somehow?

Respuesta aceptada

Marshall
Marshall el 2 de Oct. de 2014
Um, so I'll answer my own question instead of deleting in case someone comes along looking.
I found the information required here in this article by the amazing Loren Shure:
"Arrays in MATLAB are N-dimensional, with an infinite number of trailing singleton dimensions. Trailing singleton dimensions past the second are not displayed or reported on, e.g., with size. "
So I just now need to think of a different way to assess that vector... :)
  1 comentario
Marshall
Marshall el 2 de Oct. de 2014
Oh, typed and went to lunch, submitted and then found Iain's answer too.

Iniciar sesión para comentar.

Más respuestas (1)

Iain
Iain el 2 de Oct. de 2014
Matlab only really needs to know which dimensions are "nonsingular". - A scalar has infinite dimensions, all with a size of 1. - A vector has infinite dimensions, only one of which has a size other than 1.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by