Prompt user to load data file

20 views (last 30 days)
Matthew Piccolo
Matthew Piccolo on 13 Apr 2017
Answered: Nick on 13 Apr 2017
I am creating a pop-up menu as part of a final project for one of my courses. One option on this menu will ask the user to load a data file, I'm not sure how to ask a user which file they would like to use. I know how to load data files into arrays, but I don't know how to build a prompt that will ask "which file." Preferably I'd like it to open a file explorer in which you select a file, but I'm not sure if this is possible.
Here is what i have. The prompt to select a file to load into an array would be case 2.
choice = 1;
while choice ~= 11
choice = menu('Statistical Analysis','Set username','Load data file','Clear data','Set output filename','Plot histogram','Plot histogram fit','Plot probability plots','Regression of y on x','Find probability (x or z)','Find x or z','Exit')
switch choice
case 0
close all
case 1
username = input('Please input your username:\n','s')
case 2
x = load('input')
case 11
close all
end
end

Accepted Answer

Nick
Nick on 13 Apr 2017
Take a look at https://www.mathworks.com/help/matlab/ref/uigetfile.html it might be what you are looking for. You can filter by file type as well so below I look for all csv files and then load the selected file.
%Shows all files with a .csv extension
[FileName,PathName,FilterIndex] = uigetfile('.csv')
C = csvread(FileName)

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!