Filter löschen
Filter löschen

how to convert python code to matlab

2 Ansichten (letzte 30 Tage)
Yasyfa Rifiani Putri
Yasyfa Rifiani Putri am 6 Nov. 2021
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)

Antworten (1)

Chunru
Chunru am 6 Nov. 2021
% 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

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