Clear Filters
Clear Filters

Plotting graph from table using app designer

17 views (last 30 days)
I have created an app that will prompt the user to select a .txt file to read into a table, and the table is made up of seperate columns. I want to use the first column to be populate the X axis and the rest of the columns to populate the y axis in different individual lines. To clarify, if there are 4 columms there should be 3 lines with the second through fourth columns being the data that make up the points on Y axis for each line. What is the best way to go about doing this in matlab app designer?

Accepted Answer

Mohammad Sami
Mohammad Sami on 22 Jul 2020
First in your app in the design view, you will need to add an UIAxes to the app.
Thereafter you can plot on it. Add a callback to the plot button. And inside you can prompt the user to select the file.
Then you can load and plot it.
function plotButtonPushedCallback(app,event)
[filename,folder] = uigetfile('*.txt');
file = fullpath(folder,filename);
tab = readtable(file); % assuming default options work.
X = tab.(1);
Y = table2array(tab(:,2:end));
plot(app.UIAxes,X,Y);
end

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!