Prompt user to load data file

64 次查看(过去 30 天)
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

采纳的回答

Nick
Nick 2017-4-13
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by