Why can't I have parenthesis in my file name when using TEXTREAD?
1 view (last 30 days)
Show older comments
Why can't I have parenthesis in my file name when using TEXTREAD?
If I use parenthesis in my file name, TEXTREAD gives an error. For example:
textread('C:\Test(1).csv', '','delimiter', ',', 'headerlines', 1)
will return the following:
??? Error: ";" expected, "." found.
Error in ==> D:\MATLAB6p1\toolbox\matlab\iofun\textread.m
On line 155 ==> if (exist(varargin{1}) ~= 2 | exist(fullfile(cd,varargin{1})) ~= 2) & ~isempty(which(varargin{1}))
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This seems to be a bug in the TEXTREAD function. It has been reported to our development staff to be fixed in a future release of MATLAB.
As a workaround you can create a wrapper function for TEXTREAD that will take in the directory where the file is located, the name of the file, and the parameters.
The wrapper function can look like the following:
function data = newtextread(dir, file, varargin)
% This function is a wrapper function for TEXTREAD function
% provided within MATLAB. This function takes care of
% the parenthesis in the file name, which causes TEXTREAD
% to fail.
olddir = pwd;
cd(dir);
data = textread(file, varargin{:});
cd(olddir);
Please copy and paste the above code in a file named newtextread.m and save it in a directory that is on your MATLAB path. This function can be used as followed:
newtextread('c:\', 'Test(1).csv', '','delimiter', ',', 'headerlines', 1)
where the file Test(1).csv is located at c:\.
0 Comments
More Answers (0)
See Also
Categories
Find more on Programming Utilities in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!