請在同一文件夾在您的函數中添加此代碼。保存此文件start.m
FD1=getAllFiles('Dataset\your_data_folder');
for f=1:size(FD1)
im=dicomread(FD1{f});
[z,y] = med (f) %your function
end
保存此文件getAllFiles.m
function fileList = getAllFiles(dirName)
dirData = dir(dirName); %# Get the data for the current directory
dirIndex = [dirData.isdir]; %# Find the index for directories
fileList = {dirData(~dirIndex).name}'; %'# Get a list of the files
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),... %# Prepend path to files
fileList,'UniformOutput',false);
end
subDirs = {dirData(dirIndex).name}; %# Get a list of the subdirectories
validIndex = ~ismember(subDirs,{'.','..'}); %# Find index of subdirectories
%# that are not '.' or '..'
for iDir = find(validIndex) %# Loop over valid subdirectories
nextDir = fullfile(dirName,subDirs{iDir}); %# Get the subdirectory path
fileList = [fileList; getAllFiles(nextDir)];%# Recursively call getAllFiles
end
end
現在你可以拍攝圖像的hunderds來自同一個文件夾中。