from a python code to matlab code
Show older comments
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))
Accepted Answer
More Answers (2)
Chunru
on 31 Dec 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 Comments
Image Analyst
on 31 Dec 2021
Then, to print to the command window:
fprintf("Cuts under 30 :\n")
fprintf('%.2f ', cuts_under_30);
fprintf('\n')
Chunru
on 31 Dec 2021
Or simply remove the semicolon at the end of the statement.
Michael Angeles
on 31 Dec 2021
Edited: Image Analyst
on 31 Dec 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 Comment
Michael Angeles
on 31 Dec 2021
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!