フィルターのクリア

read file from uigetfile routine

2 ビュー (過去 30 日間)
Michael Angeles
Michael Angeles 2023 年 2 月 9 日
編集済み: Image Analyst 2023 年 2 月 9 日
Hi, I am trying to load a file by using the uigetfile routine but my code seems to error out...
I get the following error
Error using readmatrix (line 157)
Unable to find or open 'file1'. Check the path and filename or file permissions.
[file1,path] = uigetfile('*.csv');
if isequal(file1,0)
disp('User did not pick a file');
else
disp(['Selected WRxx',fullfile(path,file1)]);
end
WRxx_0_00A = readmatrix('file1','Range','A3:D16003'); %replace file name

採用された回答

Image Analyst
Image Analyst 2023 年 2 月 9 日
編集済み: Image Analyst 2023 年 2 月 9 日
Don't use path for the name of your folder because path is a built-in variable name. Try this:
[baseFileName, folder] = uigetfile('*.csv');
if isequal(baseFileName, 0)
disp('User did not pick a file');
return;
end
fullFileName = fullfile(folder, baseFileName);
disp(['Selected WRxx ',fullFileName]);
WRxx_0_00A = readmatrix(fullFileName,'Range','A3:D16003'); % Load data into variable.
or better:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~isfolder(startingFolder)
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
fprintf('Reading in "%s".\n', fullFileName)
WRxx_0_00A = readmatrix(fullFileName,'Range','A3:D16003');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultibody Modeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by