필터 지우기
필터 지우기

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 CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by