Posts

Showing posts with the label octave

Octave(or Matlab) sub2ind function convert to python code

Image
Clash Royale CLAN TAG #URR8PPP Octave(or Matlab) sub2ind function convert to python code I implement Matlab 'strel' function to python language. I have some difficulty converting to python code. plz let me know how to convert this function. I think numpy's ravel_multi_index function equal to sub2ind. but it dose not work well. :( Octave code degrees = 30 linelen = 5 deg90 = mod (degrees, 90); if (deg90 > 45) alpha = pi * (90 - deg90) / 180; else alpha = pi * deg90 / 180; endif ray = (linelen - 1)/2; c = round (ray * cos (alpha)) + 1; r = round (ray * sin (alpha)) + 1; line = false (r, c); m = tan (alpha); x = [1:c]; y = r - fix (m .* (x - 0.5)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% indexes = sub2ind ([r c], y, x); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% and My python code here. def strel_line(length,degree): import numpy as np from numpy import pi,cos,sin,tan,fix deg90 = degree % 90 if deg90 > 45: alpha = pi * (90 - deg90) / 180 else: a...