Data import to workspace from multiple .0 files(dot zero files)

조회 수: 2 (최근 30일)
MaheKK
MaheKK 2015년 1월 27일
댓글: MaheKK 2015년 1월 28일
Hi,
I am using following function to import data from a .0 file(dot zero file=text file) into Matlab workspace.
Now I wanted to import data from N number of .0 files, so i generated a function -importfile4.m manually from Import selection.
In a separate multiplefiles.m file I wrote the following code to repeat the same for N no. of files.
numFiles = 8; startRow = 2; endRow = inf; myData = cell(1,numFiles);
for fileNum = 1:numFiles filename = sprintf('%d.0',fileNum); Data{fileNum} = importfile4(filename,startRow,endRow); end
but i am getting the following error.
>> multiplefiles Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.
Error in importfile4 (line 37) dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
Error in multiplefiles (line 15) Data{fileNum} = importfile4(filename,startRow,endRow);
Note : Files I am using looks like the following and extension is .0
file 1 name - {3BA6AFC6-DB3F-4833-AED2-C2F147172C0D}.0 file 2 name - {4D78FD28-28D4-40A6-9C1C-277969C600AA}.0
I use Windows operating system,Please help me where am I doing wrong?
Many thanks in Advance.

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 1월 28일
Mahesh - the error message is telling you that the fopen failed for your input file. So put a breakpoint at the line in the importfile4 function where the fileID variable is initialized (probably something like fileID = fopen(filename);. Run your code and when it pauses at this line, step to the next line. What is the value of fileID? If it is negative (or zero) then MATLAB has not been able to find the file. If that is the case, then ask yourself where is this file relative to importfile4? Are they both in the same directory? If not, then you will need to include the full path to the file and not just its name.
  댓글 수: 1
MaheKK
MaheKK 2015년 1월 28일
Hi Geoff,
That helped me a lot, Thanks for your time and hints, I added the following code before fileID in order to get filename interactively and now i can see a positive integer value written in fileID.
[filename,filepath1]=uigetfile({'*.0*','Text Files'},... 'Select Data File 1'); cd(filepath1);
Thank You, Mahesh.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by