Rick T
Rick T

Reputation: 3389

Splitting up number by certain amount

I'm trying to split up numbers by a given value (4000) and have the numbers placed in an array

Example: max value given is: 8202

So the split_array should be split by 4000 unless it gets to the end and it's less than 4000 in which case it just goes to the end.

start_pos, end_pos
0,4000
4001,8001
8002,8202

so the first row in the array would be
[0 4000]
second row would be
[4001 8001]
third row would be 
[8002 8202]

please note that the max value can change from (8202) to be any other number like (16034) but never a decimal How can I go about doing this using matlab / octave

Upvotes: 1

Views: 73

Answers (1)

Mohsen Nosratinia
Mohsen Nosratinia

Reputation: 9864

This should produce what you want

n = 8202;
a = [0:4001:n; [4000:4001:n-1 n]]'

returns

a =
           0        4000
        4001        8001
        8002        8202

Upvotes: 4

Related Questions