create a menu which allows users to choose to plot simple 2d line, scatter plot or bar chart in matlab

First, create a menu that allows users to select the type of chart they want to plot. Then, depending on the user's selection, call the corresponding plot function.

Here's the code:

main.m
% Display the menu
choice = menu('Select a chart type', 'Line', 'Scatter', 'Bar');

% Generate some sample data
x = 1:10;
y = rand(1,10);

% Plot the selected chart type
switch choice
    case 1 % Line plot
        plot(x,y);
        title('Line Plot');
    case 2 % Scatter plot
        scatter(x,y);
        title('Scatter Plot');
    case 3 % Bar chart
        bar(x,y);
        title('Bar Chart');
end
406 chars
20 lines

The menu function displays a dialog box with the specified choices and returns the user's selection as an integer. Then, using a switch statement, we call the appropriate plotting function (plot, scatter, or bar) depending on the user's choice.

Note that this is just a basic example to get you started. You may want to add more features or customize the chart appearance to suit your needs.

related categories

gistlibby LogSnag