Convert for loop Matlab in python

8 views (last 30 days)
Harry Smith
Harry Smith on 6 Dec 2022
Commented: Harry Smith on 6 Dec 2022
Hello everyone, i'd like to convert my Matlab for loop in a Python for loop, but i'am a beginner in Python.
The for loop is:
step=1;
% a,c,k,h are double arrays
cellsize=100;
me=43545;
mn=54656;
x = size(a,1);
y = size(a,2);
R = size((1 : step : x),2);
C = size((1 : step : y),2);
one = zeros(3,R,C);
two = zeros(3,3,R,C);
three = zeros(3,3,R,C);
four = zeros(12,R,C);
pos = zeros(3,1);
jj = 0;
for j = 1 : step : y
jj = jj + 1;
pos(1) = me + cellsize*(j-1);
ii = 0;
for i = 1 : step : x
ii = ii + 1;
pos(2) = mn - cellsize*(i-1);
pos(3) = a(i,j);
s = S(:,i,j);
lia=LIA(:,i,j);
[q w e r] = my_function(pos,c,s,k,h);
one(:,ii,jj) = q;
two(:,:,ii,jj) = w;
three(:,:,ii,jj) = e;
four(:,ii,jj) = r;
end
end
Can you help me please?

Answers (1)

Florian Bidaud
Florian Bidaud on 6 Dec 2022
The equivalent of
for i = start:step:finish
% do something
end
is
for i in range(start, finish+1,step):
#do something
  1 Comment
Harry Smith
Harry Smith on 6 Dec 2022
Thank you. Could you help me for rest of the script?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!