What does 2nd argument mean in numel function?
1 view (last 30 days)
Show older comments
Earlier version of matlab has some extra arguments for the function numel , which said, it gives the number of subscripted elements. What does it mean? I am not able to figure it out. Even the current version supports those extra arguments , but doesn't show it in Documentation. Please Explain what it is.
a = rand(5);
numel(a , 1 , 2 , 3) % it always gives 1 as output, no matter what I try
numel(a , [1 ,2]) % Gives the length of 2nd argument
1 Comment
Adam
on 8 Jan 2015
subsref and subassign both use numel so maybe they make use of the further arguments in a way that is not generally useful for normal code.
I don't generally over-ride either of those two functions though in my classes as they can get complicated so I have never really looked into it.
Answers (1)
Guillaume
on 8 Jan 2015
if you do
numel(a, 1:10, 1:10)
it returns 100. It looks like it returns the product of the number of elements of all the arguments starting from the second one and actually ignores the first.
I don't see how that is useful.
2 Comments
Guillaume
on 8 Jan 2015
According to the earliest documentation I can find matlab used to call numel for expressions such as A{i1, i2, i3} that generate comma-separated lists, probably to know how many list elements to allocate.
I don't think it does anymore, and it looks like it's broken now as it completely ignores the size of the first argument. I would expect in the past, it would have thrown an error if the indices were out of bounds.
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!