Breaking down a large array

Hi,
I have a large array (nx1) of values that I'd like to break up into a new array. This new array takes the first 200 or so values from the original array and then only selects every 3rd value (or even a logarithmic selection) of the original array to construct the new array. I was thinking about doing this with a loop, but I was wondering if matlab had any built-in functions that could do this.
Thanks, Charles

 採用された回答

Roger Stafford
Roger Stafford 2013 年 5 月 23 日

0 投票

For spacing every third element
p = a:3:b;
For logarithmic spacing
p = round(k*a.^(1:n));
for appropriate a, k, and n. Then do this:
new_array = old_array(p);

4 件のコメント

Senaasa
Senaasa 2013 年 5 月 23 日
Those would work if I wanted to split up the entire array. What I'm trying to do is split up a portion of the array while keeping the beginning of the array (first 200 points) the same. After these first 200 points, I then want to go by some incremental amount (say 3) and splice together that result with the first 200 points to form the new array.
Walter Roberson
Walter Roberson 2013 年 5 月 23 日
p = [1:200, 202:3:length(old_array)];
Cedric
Cedric 2013 年 5 月 23 日
編集済み: Cedric 2013 年 5 月 23 日
What Roger is generating is an array of IDs/positions (that he then uses for indexing operations); you can work with these as you work with any other array; in particular, you can concatenate them, e.g.
p = [1:200, 203:3:1000] ;
or
p = [1:200, 200+3^(1:5)] ;
etc. Experiment with smaller numbers so you can easily visualize p.
Senaasa
Senaasa 2013 年 5 月 23 日
Ok, I've got it now. Thanks a lot guys

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by