winggundam
Would you like to react to this message? Create an account in a few clicks or log in to continue.

I want to load all files in a folder to matlab. How can I do this?

向下

I want to load all files in a folder to matlab. How can I do this? Empty I want to load all files in a folder to matlab. How can I do this?

發表 由 lung 周三 1月 18, 2012 1:59 pm

lung
lung
Admin

文章數 : 26067
注冊日期 : 2009-07-12

回頂端 向下

I want to load all files in a folder to matlab. How can I do this? Empty 回復: I want to load all files in a folder to matlab. How can I do this?

發表 由 lung 周三 1月 18, 2012 2:00 pm

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
lung
Admin

文章數 : 26067
注冊日期 : 2009-07-12

回頂端 向下

I want to load all files in a folder to matlab. How can I do this? Empty 回復: I want to load all files in a folder to matlab. How can I do this?

發表 由 lung 周三 1月 18, 2012 2:00 pm

% 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
lung
lung
Admin

文章數 : 26067
注冊日期 : 2009-07-12

回頂端 向下

回頂端


 
這個論壇的權限:
無法 在這個版面回復文章