When I run the following code it only shows the last file in the directory in MATLAB workspace? How do I get all the files in my directory saved in the workspace?
1 次查看(过去 30 天)
显示 更早的评论
ivsFiles = dir('*.ivs');
numfiles = length(ivsFiles);
for k = 1:103;
filename = ivsFiles(k).name;
fileID = filename;
C = textscan(filename,'%d');
end
3 个评论
采纳的回答
KSSV
2016-9-22
编辑:KSSV
2016-9-22
ivsFiles = dir('*.ivs');
numfiles = length(ivsFiles);
C = cell(numfiles,1) ; % initialize each file's data into a cell
for k = 1:numfiles;
filename = ivsFiles(k).name;
fileID = filename;
C{i} = textscan(filename,'%d');
end
Please note that, you will eat up the memory if the files are huge.
2 个评论
Walter Roberson
2016-9-22
ivsFiles = dir('*.ivs');
numfiles = length(ivsFiles);
C = cell(numfiles,1) ; % initialize each file's data into a cell
for k = 1:numfiles;
filename = ivsFiles(k).name;
fileID = fopen(filename, 'rt');
C{i} = textscan(fileID,'%d');
fclose(fileID);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!