Data import to workspace from multiple .0 files(dot zero files)
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I am using following function to import data from a .0 file(dot zero file=text file) into Matlab workspace.
Select Text File Data Using Import Tool - http://de.mathworks.com/help/matlab/import_export/import-data-interactively.html
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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!