Why does Matlab not recognize my .txt file as readable using csvread, and how do I fix it?

2 views (last 30 days)
I am trying to use Matlab in order to quickly analyze data from a group of large Excel files, so my plan was to convert them into CSV format and use the csvread function in order to import and analyze them. However, when I try to run my code it give me the following error:
"Undefined function or variable 'TestWaveform1Edit'. Error in WaveformAnalysis (line 8)"
My code is as follows:
Data = csvread(TestWaveform1Edit, 0, 0, [1 0 rowBound 8]);
"TestWaveform1Edit" is a .txt file, formatted to be readable as a .csv file, as directly saving my excel workbooks as .csv files did not work. Has anyone had this issue, and what am I doing wrong in my implementation of the csvread function? I have yet to get it to work with any files, even smaller, simpler ones that I created outside of Excel.

Accepted Answer

Adam
Adam on 20 Feb 2017
Unless TestWaveform1Edit is a variable containing the name of your file then of course this will not work. The filename needs to be provided as a string/char e.g.
Data = csvread('TestWaveform1Edit', 0, 0, [1 0 rowBound 8]);
Whether that is enough on its own I don't know. I tend to prefer to provide a full path to most files I use, but if it is on your Matlab path then it should find it, though you probably need the extension on the end too.
  1 Comment
Jack Iverson
Jack Iverson on 20 Feb 2017
I realized that, at least for my purposes, it was just as practical to manually import each csv into an array rather than automating the process in this way. However, I tried what I was doing before with your fix and it did work, so thank you for the help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!