I’m kinda confused with the smart plotter , here is some example of it
Mostrar comentarios más antiguos
Smart Plotter Program - Design an application that displays a menu to ask the user to choose whether to: (20 marks) (a) Plot the relationship between the temperature and time using bar chart using the following instructions − Load a file that contain an array of 10 days − Load a file that contain an array of 10 corresponding sales amounts at which the sales were done. − Determine the total sales and print the output. (b) Plot on the same graph for the functions f(x) = x + 3, g(x) = X2 +1, f(x)*g(x) and f(x)/g(x) for the range x values from -1 to 1. (c) Quit the Smart Plotter The user can choose then proceed to plot a simple 2D line, a scatter plot or bar chart. The program will continue displaying the menu to allow the user to choose until the user chooses to quit the application
2 comentarios
Dyuman Joshi
el 11 de Jun. de 2023
Editada: Dyuman Joshi
el 11 de Jun. de 2023
What exactly are you confused about?
What do you need help for?
Xenial
el 11 de Jun. de 2023
Respuestas (1)
Diwakar Diwakar
el 11 de Jun. de 2023
Try this code:
function smart_plotter()
while true
disp("---- Smart Plotter Menu ----")
disp("1. Plot Temperature vs Sales")
disp("2. Plot Functions")
disp("3. Quit")
choice = input("Enter your choice (1-3): ");
switch choice
case 1
plot_temperature_sales();
case 2
plot_functions();
case 3
disp("Exiting Smart Plotter...");
break;
otherwise
disp("Invalid choice. Please try again.");
end
end
end
function plot_temperature_sales()
try
temperature_file = input("Enter the file name for temperature data: ", 's');
sales_file = input("Enter the file name for sales data: ", 's');
temperature = load(temperature_file);
sales = load(sales_file);
bar(temperature, sales);
xlabel("Temperature");
ylabel("Sales");
title("Temperature vs Sales");
total_sales = sum(sales);
disp("Total sales: " + total_sales);
pause; % Pauses execution until the user closes the plot window
catch e
disp("Error: " + e.message);
end
end
function plot_functions()
x = linspace(-1, 1, 100);
f = x + 3;
g = x.^2 + 1;
fg = f .* g;
fg_div = f ./ g;
plot(x, f, 'DisplayName', 'f(x) = x + 3');
hold on;
plot(x, g, 'DisplayName', 'g(x) = x^2 + 1');
plot(x, fg, 'DisplayName', 'f(x) * g(x)');
plot(x, fg_div, 'DisplayName', 'f(x) / g(x)');
hold off;
xlabel("x");
ylabel("y");
title("Function Plots");
legend('Location', 'best');
pause; % Pauses execution until the user closes the plot window
end
smart_plotter();
4 comentarios
diyana
el 12 de Jun. de 2023
how to pass the file name
input("Enter the file name for sales data: ", 's');
diyana
el 12 de Jun. de 2023
Qusetion is for menu :( and not console based.
last ask in question is "The user can choose then proceed to plot a simple 2D line, a scatter plot or bar chart. The program will continue displaying the menu to allow the user to choose until the user chooses to quit the application"
Dyuman Joshi
el 12 de Jun. de 2023
Check out
Xenial
el 14 de Jun. de 2023
Categorías
Más información sobre MATLAB Parallel Server en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!