Effacer les filtres
Effacer les filtres

how to convert python code to matlab

2 vues (au cours des 30 derniers jours)
Yasyfa Rifiani Putri
Yasyfa Rifiani Putri le 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)

Réponses (1)

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

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by