I want to load all files in a folder to matlab. How can I do this?
winggundam :: all :: 電腦知識
第1頁(共1頁)
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
回復: I want to load all files in a folder to matlab. How can I do this?
i have a command like fopen(file1.txt),,,,,but I want to open say 10 of these files and the names vary. However, all of the files are in the same folder. Can I tell matlab to look for the folder and open everything into it? Thank you!
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
回復: I want to load all files in a folder to matlab. How can I do this?
% copy-paste the following into your command window or your function
% first, you have to find the folder
folder = uigetdir; % check the help for uigetdir to see how to specify a starting path, which makes your life easier
% get the names of all files. dirListing is a struct array.
dirListing = dir(folder);
% loop through the files and open. Note that dir also lists the directories, so you have to check for them.
for d = 1:length(dirListing)
if ~dirListing(1).isdir
fileName = fullfile(folder,dirListing(d).name); % use full path because the folder may not be the active path
% open your file here
fopen(fileName)
% do something
end % if-clause
end % for-loop
% first, you have to find the folder
folder = uigetdir; % check the help for uigetdir to see how to specify a starting path, which makes your life easier
% get the names of all files. dirListing is a struct array.
dirListing = dir(folder);
% loop through the files and open. Note that dir also lists the directories, so you have to check for them.
for d = 1:length(dirListing)
if ~dirListing(1).isdir
fileName = fullfile(folder,dirListing(d).name); % use full path because the folder may not be the active path
% open your file here
fopen(fileName)
% do something
end % if-clause
end % for-loop
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
winggundam :: all :: 電腦知識
第1頁(共1頁)
這個論壇的權限:
您 無法 在這個版面回復文章