How do I import Data from a different folder?
이전 댓글 표시
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!
답변 (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
Dropbox406
2014년 12월 13일
Image Analyst
2014년 12월 13일
list does not have the folder in it. You have to create the full filename with fullfile
fullFileName = fullfile(pwd, list(i).name);
A(:,i) = importdata(fullFileName);
Dropbox406
2014년 12월 17일
Dropbox406
2014년 12월 17일
Thorsten
2014년 12월 17일
Easy as
addpath('C:\xx\xx\data_folder\composite1.dat')
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
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!