## Can I divide a linear array by a number which larger than its size ?

Asked by Zara Khan

### Zara Khan (view profile)

on 16 Mar 2019 at 10:19
Latest activity Commented on by Image Analyst

### Image Analyst (view profile)

on 17 Mar 2019 at 15:35
I am having a cell array. Each element of the cell array is a linear array . These arrays are of different sizes. when diving each array to some equal parts then I am not getting consistent parts. Suppose I want to divide each cell array by 20. When the size is greater than 20 then its ok. but when less than 20 then I am not getting any consistent parts. I want to divide each linear array to 20 equal parts. whatever the size is I dont want any padding of values. If the array size is 1×17 and diving with 20 will give 20 equal parts . The partition size will be less than 1. How can I do this ?

Zara Khan

### Zara Khan (view profile)

on 16 Mar 2019 at 14:38
I am getting "cell array.png' cell array. Now I want to divide each cell equally to 20 partitions
Image Analyst

### Image Analyst (view profile)

on 16 Mar 2019 at 14:58
Unless you want to do some interpolation/resizing, you can't because each array in each cell is not a multiple of 20.

### KSSV (view profile)

on 16 Mar 2019 at 10:31

You interpolate your data into your desired size and then reshape. Read about interp1.

Zara Khan

### Zara Khan (view profile)

on 16 Mar 2019 at 11:01
how can I handle an entire cell array with this ? Suppose my first cell contains an array of size 1×17, diving with 20 will give a size of 0.85. Is this possible to do here ? Next cell contains 1×31 , diving with 20 again, next cell is 1×131 again diving with 20. Cell array contains 16 colums and 1000 rows . How can I loop over this process? Please help. ### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 16 Mar 2019 at 17:31

Next20 = @(V) ceil(length(V)/20) * 20;
Interp20 = @(V) interp1(V, linspace(1, length(V), Next20(V)));
Split20 = @(V) mat2cell(V, 1, 20*ones(1, length(V)/20));
new_cell = cellfun( @(V) Split20(Interp20(V)), cell_array, 'Uniform', 0);

Walter Roberson

### Walter Roberson (view profile)

on 17 Mar 2019 at 7:14
Zara Khan

### Zara Khan (view profile)

on 17 Mar 2019 at 9:52
Error using zeros
Size inputs must be scalar.
Error in @(v,N)FirstN([v(:).',zeros(1,N)],N).'