create a program to ask the user which type of graph he wishes to plot. the choices are: bar chart, line 2d or pie 3d chart. the given vector is [4, 10, 5, 7, 9 , 3, 2, 8] but can be of any size. in matlab

You can use the input function in MATLAB to ask the user for input. Then, based on the user's choice, you can plot a bar chart, a line 2D chart, or a pie 3D chart using the bar, plot, or pie functions in MATLAB, respectively.

Here's an example code:

main.m
v = [4, 10, 5, 7, 9, 3, 2, 8];

% Ask user for input
choice = input('What type of graph do you wish to plot? (1 - bar chart, 2 - line 2D, 3 - pie 3D chart): ');

% Plot graph based on user's choice
switch choice
    case 1 % Bar chart
        bar(v)
        title('Bar chart')
        xlabel('Index')
        ylabel('Value')
    case 2 % Line 2D chart
        plot(v)
        title('Line 2D chart')
        xlabel('Index')
        ylabel('Value')
    case 3 % Pie 3D chart
        pie(v)
        title('Pie 3D chart')
end
522 chars
22 lines

Note that this code assumes that the user will enter a valid choice (i.e., 1, 2, or 3). You may need to add some error handling code to handle invalid input.

gistlibby LogSnag