Borrar filtros
Borrar filtros

write down matlab command lines into python

4 visualizaciones (últimos 30 días)
Mark Sc
Mark Sc el 9 de Oct. de 2021
Respondida: Walter Roberson el 10 de Oct. de 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 comentarios
Walter Roberson
Walter Roberson el 9 de Oct. de 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 el 9 de Oct. de 2021
it's correct,
you saved me
thank you so much
How could I accept your answer

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by