フィルターのクリア

How to convert Python code into matlab

127 ビュー (過去 30 日間)
Vombarelli Neha
Vombarelli Neha 2018 年 8 月 24 日
コメント済み: Evens MONTILUS 2023 年 10 月 21 日
I have a Python code.how can I convert it into matlab code or is there any option of executing the same using matlab
  5 件のコメント
wafa derouaz
wafa derouaz 2021 年 11 月 21 日
Vombarelli Neha Please, didi you find the solution to this problem?
Evens MONTILUS
Evens MONTILUS 2023 年 10 月 21 日
import numpy as np
impot matplotlib.pyplot as plt
line=np.linspace(-5,5,1000)
#plt.plot(line,np.tanh(line), label=''tanh'')
#plt.plot(line,np.maximum(line,0), label=''sigmoid'')
plt.plot(line,1/(1+np.exp(-line)),label=''sigmoid'')
plt.legend(loc=''best'')
plt.xlabel(''z'')
#plt.ylabel(''Relu(x),tanh(x), sigmoid(x)'')
plt.ylabel(''sigmoid(z)'')

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

回答 (4 件)

Rik
Rik 2018 年 8 月 24 日
See this, or with system('python python_script.py');
This was the top result for my Google search: link
  5 件のコメント
Rik
Rik 2020 年 8 月 6 日
Read on: "I have a Python code.how can I convert it into matlab code or is there any option of executing the same using matlab".
Anyway, a strict convert is theoretically possible (since both languages are Turing-complete), although this conversion is probably either not automatic, or not effecicient. You should either re-write it completely in Matlab, or run it as Python code. Unless you find/write a good Python2Matlab function, I know there are surprisingly good converters sometimes.
Evens MONTILUS
Evens MONTILUS 2023 年 10 月 21 日
import numpy as np
impot matplotlib.pyplot as plt
line=np.linspace(-5,5,1000)
#plt.plot(line,np.tanh(line), label=''tanh'')
#plt.plot(line,np.maximum(line,0), label=''sigmoid'')
plt.plot(line,1/(1+np.exp(-line)),label=''sigmoid'')
plt.legend(loc=''best'')
plt.xlabel(''z'')
#plt.ylabel(''Relu(x),tanh(x), sigmoid(x)'')
plt.ylabel(''sigmoid(z)'')

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


Gautam Takoo
Gautam Takoo 2022 年 1 月 21 日
編集済み: Gautam Takoo 2022 年 1 月 21 日
I have a Python code.how can I convert it into matlab code or is there any option of executing the same using matlab
import cv2
from PIL import Image
import numpy as np
from glob import glob
import os
def main():
# path of the folder containing the raw images
inPath =("Z://Randomimages")
# path of the folder that will contain the modified image
outPath =("Z:/normaltogray")
for files in os.walk(inPath):
for imagePath in os.listdir(inPath):
if not imagePath.endswith(".jpg"):
print("{} file is not an expected file".format(imagePath))
continue
inputPath = os.path.join(inPath, imagePath)
img = np.array(Image.open(inputPath))
if imagePath.startswith('T1_E1'):
roi = img[1360:1470,850:2700]
elif imagePath.startswith('T1_E2'):
roi= img[1370:1450,920:2770]
gray=cv2.cvtColor(roi,cv2.COLOR_BGR2GRAY)
fullOutPath = os.path.join(outPath,imagePath)
cv2.imwrite(fullOutPath,gray)
print(fullOutPath)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Driver Function
if __name__ == '__main__':
main()
#
  2 件のコメント
Rik
Rik 2022 年 1 月 21 日
If you didn't bother reading my answer, why should I bother responding to your question?
Walter Roberson
Walter Roberson 2022 年 1 月 21 日

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


Yalew Mekonnen
Yalew Mekonnen 2022 年 1 月 24 日
This may help you. There are a number of ducoments and videos related to using MATLAB with Python.

ASHOK KUMAR MEENA
ASHOK KUMAR MEENA 2022 年 4 月 18 日
def Lagrange(x, y, n, xx):
sum = 0
for i in range(0, n + 1):
product = y[i]
for j in range(0, n + 1):
if (i != j):
product = product * (xx - x[j]) / (x[i] - x[j])
sum += product
return sum
def Trapezoidal(h, n, f):
sum = f[0]
for i in range (1, n):
sum = sum + 2 * f[i]
sum = sum + f[n]
ans = h * sum / 2
return ans

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by