How can I execute the same program on MATLAB?

1 回表示 (過去 30 日間)
horizon
horizon 2019 年 5 月 1 日
回答済み: Walter Roberson 2019 年 5 月 4 日
I would like to execute the following procedure on MATLAB.
This program is written on Python and succeeded to execute, but I'm troubled with writing it on MATLAB.
Python3.6
# -*- coding: utf-8 -*-
import time
import sys
for i in range(10):
if i == 9:
print("end")
sys.exit()
print("Hello")
time.sleep(1)

採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 4 日
for i = (1:10)-1
if i == 9
fprintf("end\n");
exit();
end
fprintf("Hello\n");
pause(1);
end
Note that sys.exit in python means to exit python, so the equivalent program quits all of MATLAB.

その他の回答 (1 件)

Dvir Haberman
Dvir Haberman 2019 年 5 月 1 日
Hi,
I found this answer helpful.
Basically, whether if it's linux of windows, you should be able to make it run just by specifying the location of the script with:
system('commandstr')
Hope this was helpful.
  1 件のコメント
horizon
horizon 2019 年 5 月 4 日
Thank you for your answer.
Unfortunately, what I would like to do is not to execute the python script on MATLAB, but to write a code whose function is almost the same as the python code.

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

カテゴリ

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