开发者

how to make a program open files of a given folder in matlab?

I am trying to write a program in matlab. after selecting a folder th开发者_JS百科e program has to open every file in that folder, it has to replace the action of selecting a folder from the user. can anybody help me? thanks


It is difficult to understand exactly what you want to do. For now, I'm assuming that you want the user to select the directory and the program will perform some operation on the files.

The best way to deal with many files is by using directory structures as returned by the built-in Matlab function dir(). Suppose that you have a directory under your current director called testdir that has several text files that you need to operate on with some function foo() (where foo() is a fictional function),

% Get the folder name from the user
dirname = uigetdir(pwd);

% Get a directory structure of all text files in that directory
dirStruct = dir(fullfile(dirname,'*.txt'));

% Loop over all files using the directory structure calling the function foo 
% the name of the file
for k=1:length(dirStruct)
    foo(fullfile(dirname,dirStruct(k).name));
end

For further information, try checking the Matlab documentation for uigetdir, uigetfile, and dir.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜