Convert for loop Matlab in python

17 ビュー (過去 30 日間)
Harry Smith
Harry Smith 2022 年 12 月 6 日
コメント済み: Harry Smith 2022 年 12 月 6 日
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
  1 件のコメント
Harry Smith
Harry Smith 2022 年 12 月 6 日
Thank you. Could you help me for rest of the script?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by