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

2 次查看(过去 30 天)
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?

采纳的回答

Marshall
Marshall 2014-10-2
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 个)

Iain
Iain 2014-10-2
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by