from a python code to matlab code
Mostra commenti meno recenti
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))
Risposta accettata
Più risposte (2)
Chunru
il 31 Dic 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 Commenti
Image Analyst
il 31 Dic 2021
Then, to print to the command window:
fprintf("Cuts under 30 :\n")
fprintf('%.2f ', cuts_under_30);
fprintf('\n')
Chunru
il 31 Dic 2021
Or simply remove the semicolon at the end of the statement.
Michael Angeles
il 31 Dic 2021
Modificato: Image Analyst
il 31 Dic 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 Commento
Michael Angeles
il 31 Dic 2021
Categorie
Scopri di più su Call Python from MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!