from a python code to matlab code
显示 更早的评论
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))
采纳的回答
更多回答(2 个)
Chunru
2021-12-31
% cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
cuts_under_30 = hairstyles(new_prices < 30);
3 个评论
Image Analyst
2021-12-31
Then, to print to the command window:
fprintf("Cuts under 30 :\n")
fprintf('%.2f ', cuts_under_30);
fprintf('\n')
Chunru
2021-12-31
Or simply remove the semicolon at the end of the statement.
Michael Angeles
2021-12-31
编辑:Image Analyst
2021-12-31
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)
类别
在 帮助中心 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!