python - Create a "counter" on matlab from 0:limit-1. The length of counter is not determined in the program -
q- create "counter" 0:limit-1 (for example if choose 3 display 0,1,2). length of counter not determined in program , should determined when being run , inputs can differ each other
this solution on python want compute on matlab. how do that?
for in range(3): print(3-i) s in range(3,-1,-1) print s so answer :
3 2 1 3 2 1 0
as dan hinted in comments above, the colon operator of matlab want.
here examples corresponding python example:
using bare colon operator:
3:-1:0 gives
ans = 3 2 1 0 which 1 4 row vector.
you'll same result with:
limit = 3; limit:-1:0 if want use basis loop:
limit = 3; = limit:-1:0 disp(i) end will output:
3 2 1 0 more do:
istart = 6; istep = -2; iend = 0; = istart:istep:iend disp(i) end which gives:
6 4 2 0
Comments
Post a Comment