Clear Filters
Clear Filters

how to convert python code to matlab

2 views (last 30 days)
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)

Answers (1)

Chunru
Chunru on 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

Community Treasure Hunt

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

Start Hunting!