how to lad in data from excel and plot a bar chart using your data in matlab designer in matlab

To load data from an Excel file and plot a bar chart using MATLAB's App Designer, you can follow these steps:

  1. Prepare your Excel file: Make sure your data is organized in rows and columns in an Excel file.

  2. In MATLAB, use the following code in App Designer to load the Excel data and plot a bar chart:

main.m
function loadAndPlotData(app)
    % Ask user to select the Excel file
    [file, path] = uigetfile('*.xlsx', 'Select an Excel file');
    
    if isequal(file,0)
        disp('User selected Cancel');
    else
        % Read the data from the Excel file
        data = readtable(fullfile(path, file));
        
        % Assuming your Excel file has columns named 'Category' and 'Values'
        categories = data.Category;
        values = data.Values;
        
        % Plot a bar chart
        bar(app.UIAxes, categories, values);
        xlabel(app.UIAxes, 'Categories');
        ylabel(app.UIAxes, 'Values');
        title(app.UIAxes, 'Bar Chart');
    end
end
666 chars
22 lines
  1. Add a Button in your App Designer UI: Add a Button component in the App Designer figure and set its Callback to the loadAndPlotData function.

  2. Run the App Designer: Run your App Designer app and click the button to load the data from the Excel file and plot the bar chart.

This code will allow the user to select an Excel file, read the data from the selected file, and plot a bar chart using the data.

gistlibby LogSnag