フィルターのクリア

Do you have a suggestion for a name of my function?

2 ビュー (過去 30 日間)
Jos (10584)
Jos (10584) 2016 年 3 月 22 日
コメント済み: Stephen23 2016 年 3 月 31 日
I have written a nice little function which I would like to put on the File Exchange. However, I am still looking for a short and decent name for it. So I thought to ask here, for inspiration.
The function takes a vector that can contain consecutive identical elements. It returns an index vector that (re-)starts counting from 1 whenever V changes. An example
V = [10 10 10 4 4 10 9 9 9 9 9]
% and a call to MyFunction(V) returns
[ 1 2 3 1 2 1 1 2 3 4 5]
Any suggestions are welcome!
  1 件のコメント
John D'Errico
John D'Errico 2016 年 3 月 22 日
編集済み: John D'Errico 2016 年 3 月 22 日
This is sometimes the hardest part of writing a function - what to call it. You want a memorable name, since the user needs to be able to use it, and this helps improve user code readability. A short name would be nice of course. Unused is important too.

サインインしてコメントする。

採用された回答

Charles Dunn
Charles Dunn 2016 年 3 月 22 日
This is similar to Run Length Coding (https://en.wikipedia.org/wiki/Run-length_encoding). You could call it RunLengthCounter
  1 件のコメント
Jos (10584)
Jos (10584) 2016 年 3 月 24 日
Alas, no option to accept several answers, but this put me on the track of runs.

サインインしてコメントする。

その他の回答 (5 件)

Walter Roberson
Walter Roberson 2016 年 3 月 23 日
"BoatyMcBoatFace" (Google it if you missed this current event ;-) )

Stephen23
Stephen23 2016 年 3 月 22 日
編集済み: Stephen23 2016 年 3 月 23 日
Nice idea, sometimes I have needed an efficient tool to do exactly that!
Is there any similar inbuilt function? There seems the be little precedent for the name.
The term "run" is commonly used to describe contiguous sequences of one value (e.g. RLE). I find count alone is a little bit misleading, as the function does not count the runs themselves, rather the elements within each run.... however adding the prefix "re" makes it clear that this is no ordinary run counter:
runrecount
The "shape" of the output also implies some possible names:
runsteps
runstairs
and some slightly more esoteric names (aka geek humor):
penrosecount
eschercount
EDIT:
runstepcount
runscountidx

Jos (10584)
Jos (10584) 2016 年 3 月 23 日
編集済み: Jos (10584) 2016 年 3 月 23 日
Thanks for the inspiration!
What about runindex? Or is this confusing with regard to existing functions?
  3 件のコメント
Jos (10584)
Jos (10584) 2016 年 3 月 23 日
Not so sure. What is cumulative about it?
Jan
Jan 2016 年 3 月 23 日
It is a cumsum(ones()) with restarts.
The runs are repeating sequences: stammercount
I prefer runindex.

サインインしてコメントする。


Chad Greene
Chad Greene 2016 年 3 月 30 日
How about ratchet.
  1 件のコメント
Stephen23
Stephen23 2016 年 3 月 31 日
+1 outside the box and into the gear chain.

サインインしてコメントする。


Jos (10584)
Jos (10584) 2016 年 3 月 24 日
Thanks all! Nice to see, you all agree that RUN (or boat) should be part of the function name. I'll use runindex as the function "indexes runs".
It can also do simple run-length encoding.

カテゴリ

Help Center および File ExchangePropagation and Channel Models についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by