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

1 回表示 (過去 30 日間)
Xenial
Xenial 2023 年 6 月 11 日
コメント済み: Xenial 2023 年 6 月 14 日
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 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 6 月 11 日
編集済み: Dyuman Joshi 2023 年 6 月 11 日
What exactly are you confused about?
What do you need help for?
Xenial
Xenial 2023 年 6 月 11 日
i dont get the question

サインインしてコメントする。

回答 (1 件)

Diwakar Diwakar
Diwakar Diwakar 2023 年 6 月 11 日
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 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 6 月 12 日
Check out
- inputdlg for creating a menu
- switch, case, otherwise for proceeding with the option selected by user.
Xenial
Xenial 2023 年 6 月 14 日
sr for this late response but tk u so much , i appreciate this mman

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by