2014-10-02 15 views
-2
Let we have vector in Matlab such as 

V = 
    0.000178395155017 
    0.000213248167386 
    0.000453830296775 
    *0.000954267024225 
    0.001985203786879 
    0.002752603423106 
    0.004236131760631 
    0.005323800592906 
    0.004742807895286 
    0.005770068613768 
    0.006502644472601 
    0.007193873735489 
    0.006799579314313 
    0.007976014911026 
    0.007799267839386 
    0.008907651205854 
    0.009190413742866 
    0.008776108424259 
    0.008578897868764 
    0.009250162682559 
    0.008646692914164 
    0.008053809730819 
    0.007451047998031 
    0.006729120942615 
    0.005979207722644 
    0.007134289275269 
    0.005186062958380 
    0.005902382106719 
    0.007762189959679 
    0.008579238141806 
    0.009485819832702 
    0.009780236553648 
    0.010538511758940 
    0.012865379338644 
    0.011390556215603 
    0.010804154725939 
    0.010290545066940 
    0.009868360169125 
    0.009357083973682 
    0.008724843328595 
    0.008560695909341 
    0.008784388594649 
    0.008739349797176 
    0.008670604330509 
    0.008753566233007 
    0.008490628616888 
    0.008003101497979 
    0.008389140601319 
    0.007282172470936 
    0.006743970005005 
    0.006452902620905 
    0.005895958422668 
    0.006326020573140 
    0.005740103704853 
    0.005142834616900 
    0.004407465481546 
    0.003835738957490 
    0.004510955842245 
    0.003693705366274 
    0.002915993815608 
    0.002889010498571 
    0.003093844935832 
    0.004282403818479 
    0.003970929347537 
    0.002819774971736 
    0.003095369398698 
    0.002920594268954 
    0.002431265415582 
    0.001949299679935 
    0.001496954638334 
    0.001096892239592 
    0.001092281820070 
    0.000790749599802 
    0.000893827364410 
    0.001334675844874 
    0.001196368539888 
    0.001160349994386 
    0.001020290171146 
    0.001112407234178 
    0.001747377249787 
    0.002765678114897 
    0.003478849585666 
    0.005355127628032 
    0.004986389269550 
    0.005947847852449 
    0.006157789251547 
    0.006181425650566 
    0.006194151127049 
    0.006269927746287 
    0.006769754494212 
    0.007712318414790 
    0.008651586166082 
    0.008790606282214 
    0.009736113450469 
    0.011185160343747 
    0.012691072774672 
    0.010504478607987 
    0.014389683527318 
    0.014831212205190 
    0.028483974800043 
    0.011080767592010 
    0.011092374038746 
    0.012487511417703 
    0.013592769613900 
    0.023109284793639 
    0.011965905202027 
    0.012215762791363 
    0.013202467569807 
    0.011692397524803 
    0.011053425496442 
    0.010772141978943 
    0.010246937424879 
    0.0099733483767118 
    0.009945578183562 
    0.010512885752603 
    0.009531902580105 
    0.008066298613627 
    0.007407338182258 
    0.007934227536212 
    0.008839106853309 
    0.007141630457420 
    0.005890234651479 
    0.005777682702918 
    0.005975075824875 
    0.007650395349746 
    0.007857392419299 
    0.005786229253901 
    0.005200025773704 
    0.004125852007666 
    0.004066689824078 
    0.003581520984740 
    0.001457233291953 
    0.001322814038819 
    0.001253430603776 
    0.002493349764335 
    0.001702719375177 
    0.001556075727362 
    0.001200788268232 
    0.000940090552841 
    0.002078710051336 
    0.001014764365464 
    0.000954943700664 
    0.001276066704394 
    0.001359265944949 
    0.001204978086943 
    0.001593370287575 
    0.001547390763560 
    0.000930577956978 
    0.000916566445246 
    0.000546925307518 
    0.013565059409590 
    0.001282356857566 
    0.015602976997836 
    0.001499511920717 
    0.001586946634746 
    0.014156830819098 
    0.000291360243454 
    0.000429438521866 
    0.000462155358170 
    0.000362561191605 
    0.000657801010925 
    0.000593844882183 
    0.000609582362382 
    0.000310044384822 
    0.000342618178403 
    0.000282871074224 
    0.000314326548349 
    0.000204414827855 
    0.000337206866696 
    0.000532099888764 
    0.001193470342198 
    0.001296110099774 
    0.000872141517716 
    0.000700042872179 
    0.000881365833141 
    0.000373364170668 
    0.000425611062469 
    0.001421790419507 
    0.000852308546181 
    0.000815064422325 
    0.000504599352342 
    0.000700524140014 
    0.000870732973155 
    0.000714061606598 
    0.001035552251181 
    0.001149954823243 
    0.001055911091689 
    0.001199405112898 
    0.001783769543970 
    0.002409901173348 
    0.003498367375372 
    0.003703495953811 
    0.006277776686302 
    0.011652755634052 
    0.010083799009042 
    0.040863796019376 
    0.013614001128299 
    0.011042432683334 
    0.015305185452370 
    0.012711371813255 
    0.016268067330822 
    0.017370177368730 
    0.019331483583318 
    0.014673338103928 
    0.017693568446981 
    0.016892965150834 
    0.014088831405978 
    0.017200144763667 
    0.014169123504048 
    0.010078177083794 
    0.014268458659556 
    0.011690206086017 
    0.006562739851251 
    0.016466509298505 
    0.015914670918691 
    0.005624098695020 
    0.017555623339083 
    0.013692853335518 
    0.004491863547507 
    0.015326207984803 
    0.014740709288865 
    0.003199262301369 
    0.013665227028721 
    0.052745092682123 
    0.029889776608225 
    0.008659506247240 
    0.008589034126194 
    0.007785146195475 
    0.007151058968527 
    0.006980966929187 
    0.005799220068642 
    0.005386071463278 
    0.004896307509138 
    0.004818382921265 
    0.359464 
    0.004383594039787 
    0.003923666862792 
    0.003524680860004 
    0.003014782806900 
    0.002558267907671 
    0.002794987126812 
    0.003018175443714 
    0.003166769934104 
    0.004138527203301 
    0.004310037290568 
    0.004610838173675 
    0.004947713276471 
    0.005083932336596 
    0.00523670
    0.004687780786133 
    0.004564827415894 
    0.004302650724049 
    0.004270824001320 
    0.003937584195932 
    0.003911947276786 
    0.003620705359817 
    0.003151576407325 
    0.002751470077629 
    0.002669908472863 
    0.002232914262935 
    0.002069299781104 
    0.001979860796735 
    0.001601476811607 
    0.000301142580668 
    0.68102647 
    0.000390207925071 
    0.000210753154473 
    0.000387358708178 
    0.000241971967384 
    0.000366525972307 
    0.000619750196280 
    0.000412347959310 
    0.000544608934404 
    0.001311532428278 
    0.000736536458620 
    0.000523889409829 
    0.000492076015774 
    0.000297176544828 
    0.000195452121510 
    0.000292051729488 
    0.000759425298714 
    0.004267105657429 
    0.000192598592911 
    0.000235881092079 
    0.000209623369819 
    0.000160795350619 
    0.000118611207140 
    0.000253937140734 
    0.000229140021426 
    0.000132672582131 
    0.000185947357453 
    0.000336849580242 
    0.000161741284909 
    0.000212296295172 
    0.000129317114703 
    0.000078122221464 
    0.000139606283922 
    0.000074030291037 
    0.000273018975900 
    0.000084307182558 

我们的目标是将其分解为其他矢量。 分拆的标准是:当某个数字发生变化时,将一个矢量分成若干个矢量

1-元件V(i)V(i+1)的变化至少为10e-1。

它的索引存储到一个新的向量W并且如果:

2-它们在指数的差异大于30,即,W(j) - W(j+1) > 30

如果这两个条件都满足,则向量将被拆分,直到索引i。否则会被留下。 例如,在给定的载体,输出指数应为:

[4, 75, 185] 

其中会有4个载体:

V1 = [1:4] 
V2 = [4:75] 
v3 = [75:185] 
V4 = [185:300] 

你会想到什么选择的公差或具有标准是什么? 任何想法真的很感激。

+2

请发表您的输入所需的输出。 – thewaywewalk 2014-10-02 10:15:28

+1

请相应地编辑你的问题,不要在评论中发布它 - 否则会变得杂乱;)问题是,你不知道你会得到多少新的载体,所以存储结果会不会更好在单元格数组中'output = {[0.0003,0.0008,0.0019,0.0027,0.0034]; ...; ...}' – thewaywewalk 2014-10-02 10:17:05

+0

@thewaywewalk顺便提一下,你对单元阵列的建议很好。 – Royeh 2014-10-02 10:32:45

回答

2

我想你想要的是:

V = [0.0003,0.0008,0.0019,0.0027,0.0034,0.0103,0.0110,0.0106,0.0113,0.0134,0.0143,0.0148,0.0152,0.0156,0.00166,0.00172,0.0174,0.0195,0.0193,0.000195,0.00021] 

digit = 2; 

output = accumarray(cumsum(logical([0; diff(floor(10^digit*V(:)))]))+1,V,[],@(x) {x}) 

给你一个单元阵列。

output = 

    [5x1 double] 
    [9x1 double] 
    [2x1 double] 
    [3x1 double] 
    [2x1 double] 

enter image description here

一些解释相关:

%// get the important digit 
digs = floor(10^digit*V(:)); 
%// see where it changes 
d = [0; diff(digs)]; 
%// convert to 0s and 1s and cumsum them up 
subs = cumsum(logical(d))+1; 
%// to get the subs for accumarray 
output = accumarray(subs,V,[],@(x) {x}) 
+0

+1不错。做得好...... – kkuilla 2014-10-02 10:35:54

+0

在'V = V.''中转换'V'有什么好处? – kkuilla 2014-10-02 10:37:29

+0

@kkuilla你需要准确的列向量。但为了避免这一问题,我做了一些小改动。 – thewaywewalk 2014-10-02 10:41:04