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
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
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 个评论
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 Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!