Splitting a Vector Into Groups
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I need to take in the vector A, and automatically split it up, based on a number around 60-62, without knowing how many groups I want to form.
I have a length vector:
 A = [4.4708
   10.6795
   16.9590
   23.8035
   30.6478
   36.2647
   40.7722
   43.1111
   45.6896
   51.9593
   60.6814
   66.8974
   73.1607
   79.9436
   86.7766
   92.3354
   96.8187
   99.1592
  101.5261
  107.7138
  115.3084
  121.4887
  127.7691
  134.6187
  141.4633
  147.0742
  151.5830
  153.9290
  156.2800
  162.4587
  168.5842
  174.7650
  181.0298
  187.8266
  194.6664
  200.1939
  204.6659
  207.0010
  209.3573
  215.5136]
Elements in A are in meters.
Now I have broken it up by using the following command:
v=min(A):61:max(A);
and gives the following output:
ans =
    4.4708   65.4708  126.4708  187.4708
Which is close but not exact. First is it possible?
The elements that I am looking for are:
    4.4708    60.6814   115.3084  168.5842
I would need to do something similiar to another vector:
1.0222
    8.2938
   17.3975
   26.5394
   37.4131
   48.7097
   51.4079
   61.0677
   67.3565
   76.1626
   85.4651
   94.6554
  105.5474
  116.9902
  119.6214
  129.4068
  133.8319
  141.0227
  150.2807
  159.4565
  170.3328
  181.7071
  184.2469
  193.9713
  197.6725
  204.9526
  214.0602
  223.1639
  233.9971
  245.3746
  247.9699
  257.6174
  260.9988
  268.4480
  277.6225
  286.7506
  297.5619
  308.9268
  311.5883
  321.1841
  328.9418
  337.9682
  347.0968
  356.2223
  367.0407
  378.4586
  381.1692
  390.4907
With an output of:
1.0222 61.0677 133.8319 204.9526 268.4480 347.0968
But using the command I mentioned would give:
v =
Columns 1 through 6
    1.0222   62.0222  123.0222  184.0222  245.0222  306.0222
Column 7
367.0222
0 件のコメント
採用された回答
  Azzi Abdelmalek
      
      
 2013 年 3 月 26 日
        
      編集済み: Azzi Abdelmalek
      
      
 2013 年 3 月 26 日
  
      v=min(A):61:max(A);
for k=1:numel(v)
  [~,idx]=min(abs(A-v(k)));
  out(k)=A(idx)
end
3 件のコメント
  Image Analyst
      
      
 2013 年 3 月 26 日
				That was the question I had. it's not clear where he stops (it's not the max of A) and how he comes up with the step size (for example either 61 as in the first example, or 56.2106 which is 60.681-4.4708 that he wants in his second example).
その他の回答 (1 件)
  Image Analyst
      
      
 2013 年 3 月 26 日
        
      編集済み: Image Analyst
      
      
 2013 年 3 月 26 日
  
      It's not clear what you want to do but I think linspace() might be what you are looking for. You give it a min value and a max value, and a number of elements in the output array that you want and it builds it for you.
>>out = linspace(4.4708, 168.5842, 4)
out =
       4.4708   59.1752666666667    113.879733333333  168.5842
2 件のコメント
  Image Analyst
      
      
 2013 年 3 月 26 日
				It seems that Azzi figured out what you want and solved your problem because you marked it as Accepted.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


