How do I import Data from a different folder?
17 次查看(过去 30 天)
显示 更早的评论
So I can't change the directory of the data files so need a way of changing where matlab looks for the data.
The code I have so far is:
list = dir ('data_folder/*.dat'); |%where the .dat files are|
[~,index] = sortrows({list.date}.'); list = list(index); clear index |%Sorts them out by date|
for i = 1:length(list);
A(:,i) = importdata(list(i).name);
end
Thank you so much for your help!
0 个评论
回答(3 个)
Image Analyst
2014-12-13
Try this:
% Get path to a sub folder off the current working directory.
filePattern = full file(pwd, 'data_folder/*.dat');
list = dir (filePattern );
You can replace pwd by any hard coded string if you want, or else call uigetdir() to let the user browse.
4 个评论
Suhas gowda
2023-5-6
This works well for me
[file,path] = uigetfile('*.mat'); % opens file selection dialog box. You may choose data from different folder
A=importdata(strcat(path,file)); % data will be imported from the specified path
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!