Convert for loop Matlab in python

14 次查看(过去 30 天)
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?

回答(1 个)

Florian Bidaud
Florian Bidaud 2022-12-6
The equivalent of
for i = start:step:finish
% do something
end
is
for i in range(start, finish+1,step):
#do something

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by