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!