Effacer les filtres
Effacer les filtres

write down matlab command lines into python

4 vues (au cours des 30 derniers jours)
Mark Sc
Mark Sc le 9 Oct 2021
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 commentaires
Walter Roberson
Walter Roberson le 9 Oct 2021
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 le 9 Oct 2021
it's correct,
you saved me
thank you so much
How could I accept your answer

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Oct 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by