フィルターのクリア

What does 2nd argument mean in numel function?

1 回表示 (過去 30 日間)
Gautam
Gautam 2015 年 1 月 8 日
コメント済み: Adam 2015 年 1 月 8 日
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 Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by