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?

조회 수: 3 (최근 30일)
ivsFiles = dir('*.ivs');
numfiles = length(ivsFiles);
for k = 1:103;
filename = ivsFiles(k).name;
fileID = filename;
C = textscan(filename,'%d');
end
  댓글 수: 3
Anuradha Bhattacharya
Anuradha Bhattacharya 2016년 9월 22일
But I have files ra1001 to ra1150. How do I open and read all the files in the directory? Thanks for your help.
Anuradha Bhattacharya
Anuradha Bhattacharya 2016년 9월 22일
I tried this code:
ivsFiles = dir('*.ivs');
numfiles = length(ivsFiles);
for k = 1:103;
filename = ivsFiles(k).name;
fileID = filename;
fid = fopen('ra%d.ivs',k);
C = textscan(fid,'%d');
fclose(fid);
end
It is giving error:
Error using fopen Invalid permission.
My files do not have any password settings on them.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
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
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 CenterFile 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!

Translated by