フィルターのクリア

write down matlab command lines into python

4 ビュー (過去 30 日間)
Mark Sc
Mark Sc 2021 年 10 月 9 日
回答済み: Walter Roberson 2021 年 10 月 10 日
I am trying to write small part of command lines into python as I am still new and not sure if I am able to do so or not,
clc
z=4;
nu_z=1;
t_MF = [0.1,.12,.2]
t_ID = [1,2,1,1]
x = z*nu_z;
r = 0;
p = zeros(1,x);
for i = 1:z
for j = 1:nu_z
p(r+j) = t(D(i))/nu_z;
end
r = r+nu_z;
end
I tried with python as the following but I got the following error:
I got the following error: IndexError: index 8 is out of bounds for axis 0 with size 8
import numpy as np
z = 4
nu_z = 2
x = z*nu_z
r = 0
t = np.array([0.1,.12,.2])
D = np.array([0,1,0,0])
p = np.zeros((1,x))
for i in range(z):
for j in range(nu_z):
print(j)
p[r+j] = t[D[i]]/nu_z
r = r+nu_z
  4 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 9 日
I have rarely used python, so I am not certain, but I think it would be
import numpy as np
z = 4
nu_z = 2
x = z*nu_z
r = 0
t = np.array([0.1,.12,.2])
D = np.array([0,1,0,0])
p = np.zeros((1,x))
for i in range(z):
for j in range(nu_z):
print(j)
p[r+j] = t[D[i]]/nu_z
r = r+nu_z
Mark Sc
Mark Sc 2021 年 10 月 9 日
it's correct,
you saved me
thank you so much
How could I accept your answer

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 10 日
I have rarely used python, so I am not certain, but I think it would be
import numpy as np
z = 4
nu_z = 2
x = z*nu_z
r = 0
t = np.array([0.1,.12,.2])
D = np.array([0,1,0,0])
p = np.zeros((1,x))
for i in range(z):
for j in range(nu_z):
print(j)
p[r+j] = t[D[i]]/nu_z
r = r+nu_z

その他の回答 (0 件)

カテゴリ

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