フィルターのクリア

how to convert python code to matlab

2 ビュー (過去 30 日間)
Yasyfa Rifiani Putri
Yasyfa Rifiani Putri 2021 年 11 月 6 日
Hi, all! I've a problem when converting the python code to MATLAB. Below is my python code, can you help?
import random
import statistics
shadow = []
for i in range(20):
x = random.randint(1, 20)
shadow.append(x)
shadow_mean = statistics.mean(shadow)
shadow_st_dev = statistics.stdev(shadow)
shadow_value = np.random.normal(loc=shadow_mean, scale=shadow_st_dev, size=20)

回答 (1 件)

Chunru
Chunru 2021 年 11 月 6 日
% import random
% import statistics
% shadow = []
% for i in range(20):
% x = random.randint(1, 20)
% shadow.append(x)
shadow = randi([1 20], [20 1]);
% first [1 20] is range of rand num;
% second [20 1] is the size of shadow
shadow_mean = mean(shadow)
shadow_mean = 10.3500
shadow_st_dev = std(shadow)
shadow_st_dev = 4.6143
  1 件のコメント
Yasyfa Rifiani Putri
Yasyfa Rifiani Putri 2021 年 11 月 6 日
thank you! it works

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by