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

2 次查看(过去 30 天)
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