您好我是MATLAB的新手,我想知道这个功能实际上是做什么的。该功能是从上一个问题复制过来的,这个问题帮我解决了问题,找到了连续数字的频率。
链接: Series of consecutive numbers (different lengths)
d=[3 2 4 2 2 2 3 5 1 1 2 1 2 2 2 2 2 9 2]
q = diff([0 d 0] == 2);
v = find(q == -1) - find(q == 1);
答案 0 :(得分:4)
让我们一步一步来。
你有一个数组NPE
:
03-17 13:14:34.667 18799-18799/com.google.googlemediaframeworkdemo.demo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.googlemediaframeworkdemo.demo, PID: 18799
java.lang.NullPointerException
at com.google.android.libraries.mediaframework.exoplayerextensions.RendererBuilderFactory.createRendererBuilder(RendererBuilderFactory.java:34)
at com.google.android.libraries.mediaframework.layeredvideo.LayerManager.<init>(LayerManager.java:78)
at com.google.android.libraries.mediaframework.layeredvideo.SimpleVideoPlayer.<init>(SimpleVideoPlayer.java:112)
at com.google.android.libraries.mediaframework.layeredvideo.SimpleVideoPlayer.<init>(SimpleVideoPlayer.java:81)
at com.google.googlemediaframeworkdemo.demo.adplayer.ImaPlayer.<init>(ImaPlayer.java:388)
at com.google.googlemediaframeworkdemo.demo.adplayer.ImaPlayer.<init>(ImaPlayer.java:434)
at com.google.googlemediaframeworkdemo.demo.adplayer.ImaPlayer.<init>(ImaPlayer.java:467)
at com.google.googlemediaframeworkdemo.demo.MainActivity$1.onItemClick(MainActivity.java:81)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1152)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
at android.widget.AbsListView$3.run(AbsListView.java:3865)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
03-17 13:14:34.803 18799-18861/com.google.googlemediaframeworkdemo.demo D/dalvikvm: threadid=17: interp stack at 0x56eb0000
03-17 13:14:34.803 18799-18861/com.google.googlemediaframeworkdemo.demo D/dalvikvm: init ref table
03-17 13:14:34.803 18799-18861/com.google.googlemediaframeworkdemo.demo D/dalvikvm: init mutex
03-17 13:14:34.903 18799-18861/com.google.googlemediaframeworkdemo.demo D/MediatekClassFactory: createInstance(): Begin = 9861250
03-17 13:14:34.904 18799-18861/com.google.googlemediaframeworkdemo.demo D/MediatekClassFactory: create Instance with : interface com.mediatek.common.telephony.IOnlyOwnerSimSupport
03-17 13:14:34.912 18799-18861/com.google.googlemediaframeworkdemo.demo W/MediatekClassFactory: Tablet not exist!, Get obj from default class
03-17 13:14:34.916 18799-18861/com.google.googlemediaframeworkdemo.demo D/MediatekClassFactory: create Instance from tablet library : com.mediatek.tb.telephony.OnlyOwnerSimSupport
03-17 13:14:34.920 18799-18861/com.google.googlemediaframeworkdemo.demo D/MediatekClassFactory: createInstance(): End = 9861267
并申请
d
这取d=[3 2 4 2 2 2 3 5 1 1 2 1 2 2 2 2 2 9 2]
的导数。基本上它需要所有数字的导数为2. q = diff([0 d 0] == 2);
的结果是:
[0 d 0] == 2
你可以看到,只要原始向量中有2,就有1,并且它在乞讨时为0,最后为0。如果我们通过[0 d 0] == 2
:
0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1 1 1 0 1 0
只要原始矢量中的2出现,并且当消失时为-1,则得1。最后一行只找到1,只找到-1,并减去它们出现的索引,这样你现在可以在它们之间有多少个数字。 1表示“数字2开始”,-1表示“不再连续数字2”,这将为您提供连续2个系列的长度。
q = diff([0 d 0] == 2)
在开始时有一个2,然后是一系列的3 2s,然后是另一个单一的,然后是5来,并以9分开,最后一个来。