Azzera filtri
Azzera filtri

Convert for loop Matlab in python

11 visualizzazioni (ultimi 30 giorni)
Harry Smith
Harry Smith il 6 Dic 2022
Commentato: Harry Smith il 6 Dic 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?

Risposte (1)

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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by