from a python code to matlab code
Afficher commentaires plus anciens
how can I convert the following code to matlab code?
cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
print("Cuts under 30: " "{}".format(cuts_under_30))
Réponse acceptée
Plus de réponses (2)
Chunru
le 31 Déc 2021
% cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
cuts_under_30 = hairstyles(new_prices < 30);
3 commentaires
Image Analyst
le 31 Déc 2021
Then, to print to the command window:
fprintf("Cuts under 30 :\n")
fprintf('%.2f ', cuts_under_30);
fprintf('\n')
Chunru
le 31 Déc 2021
Or simply remove the semicolon at the end of the statement.
Michael Angeles
le 31 Déc 2021
Modifié(e) : Image Analyst
le 31 Déc 2021
hairstyles = ["bouffant", "pixie", "dreadlocks", "crew", "bowl", "bob", "mohawk", "flattop"];
prices = [30, 25, 40, 20, 20, 35, 50, 35];
last_week = [2, 3, 5, 8, 4, 4, 6, 2];
total_price = sum(prices)
average_price = mean(prices)
new_prices = prices()-5;
total_revenue = sum(prices.*last_week)
average_revenue = total_revenue/7
cuts_under_30 = last_week(new_prices < 30) % the number of haircuts under $30
hairstyles (new_prices < 30) % the styles of haircuts under $30
new_prices(new_prices < 30)
1 commentaire
Michael Angeles
le 31 Déc 2021
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!