What does 2nd argument mean in numel function?

2 次查看(过去 30 天)
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 个评论
Adam
Adam 2015-1-8
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.

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2015-1-8
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 个评论
Gautam
Gautam 2015-1-8
yeah , getting it
numel(a , [2 , 3 , 6 , 8] , [3 , 2 , 9] , [1 ,2])
ans =
24
But , still what sense does it makes? There must be some usage of it. Thanks for the reply
Guillaume
Guillaume 2015-1-8
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.

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by