-3

I'm trying to translate a matlab code, and I'm strugeling to translate this part of the code:

[data;SS(ind-1:-1:ind-9)']

In the following context:

SS = 1:288
year = 1:288
data = [];
for ind = 10:length(year)
    data = [data;SS(ind-1:-1:ind-9)'];
end

What I've done at the moment is:

SS = range(1,288);
year = range(1,288);

data = [];

for ind in range(10,length(year)):
    data.append(######)   # code to translate
PeCaDe
  • 277
  • 1
  • 8
  • 33

1 Answers1

2

EDIT: (Output Correction, wrong parameters)

1:288 is in python list(range(1,289)) or if you use numpy numpy.arange(1,289).

For index access you have to know, that matlab starts with 1, python with 0, so SS(ind-1:-1:ind-9) becomes SS[ind-2:ind-11:-1]

SS = list(range(1,289))
data = []
for ind in range(9,len(SS)):
    data.append(SS[ind-9:ind][::-1])

or using numpy:

data = numpy.arange(9,0,-1)[None,:] + numpy.arange(279)[:, None]
PeCaDe
  • 277
  • 1
  • 8
  • 33
Daniel
  • 42,087
  • 4
  • 55
  • 81
  • thx but the result is not the same, the dimension in matlab is 2511 on the contrary in python youre creating a 271 len of 7 items (1953). – PeCaDe May 13 '17 at 09:43