Filter löschen
Filter löschen

write down matlab command lines into python

4 Ansichten (letzte 30 Tage)
Mark Sc
Mark Sc am 9 Okt. 2021
Beantwortet: Walter Roberson am 10 Okt. 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 Kommentare
Walter Roberson
Walter Roberson am 9 Okt. 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 am 9 Okt. 2021
it's correct,
you saved me
thank you so much
How could I accept your answer

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by