I’m kinda confused with the smart plotter , here is some example of it
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Dyuman Joshi
am 11 Jun. 2023
Bearbeitet: Dyuman Joshi
am 11 Jun. 2023
What exactly are you confused about?
What do you need help for?
Antworten (1)
Diwakar Diwakar
am 11 Jun. 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();
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!