I’m kinda confused with the smart plotter , here is some example of it

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 Comments

What exactly are you confused about?
What do you need help for?

Sign in to comment.

Answers (1)

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 Comments

how to pass the file name
input("Enter the file name for sales data: ", 's');
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"
Check out
- inputdlg for creating a menu
- switch, case, otherwise for proceeding with the option selected by user.
sr for this late response but tk u so much , i appreciate this mman

Sign in to comment.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Tags

Asked:

on 11 Jun 2023

Commented:

on 14 Jun 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!