opening excel .csv

2 views (last 30 days)
Dylan Mecca
Dylan Mecca on 7 Feb 2018
Commented: Bob Thompson on 7 Feb 2018
Hi everyone,
I've been working on a project that would allow me to pull data from a .csv file to later plot. The problems I have been running into include not allowing anything to come through: csvread(filename), or even xlsread(filename) just throw errors. I'm under the impression that these two commands should be able to work fine, however, they do not work at all. I don't know if I'm using them incorrectly, or if my 2014a version matlab isn't liking excel 2016? Could it possibly have anything to do with the fact that my file name(20180122Mx00_Go-Stop CE(US)0001.csv) has a space in it?
When using xlsread('myfilename.csv'), I get the following error:
  • Error using xlsread (line 128)
  • XLSREAD unable to open file '20180122Mx00_Go-Stop CE(US)0001.csv'.
  • File 'C:\Users\vc043111\Documents\MATLAB\20180122Mx00_Go-Stop CE(US)0001.csv' not found.
  • Error in prac5 (line 5)
  • Pattern = xlsread('20180122Mx00_Go-Stop CE(US)0001.csv');
When using csvread('myfilename.csv'), I get this following error:
  • Error using csvread (line 34)
  • File not found.
  • Error in prac5 (line 5)
  • Pattern = csvread('20180122Mx00_Go-Stop CE(US)0001.csv');
xlsread('myfilename') will work just fine if I'm using an .xls file, and I understand that changing my spreadsheet file type to that would solve that problem, but I want the user to have the least amount of steps as possible.
  1 Comment
Bob Thompson
Bob Thompson on 7 Feb 2018
Most likely it simply means that the commands are unable to identify the file properly due to some form of directory error. You could double check the file name, and make sure it is within your matlab path.
To avoid this issue I personally like to use uigetfile() to select the file within the code. This also prevents me from needing to manually change the file name in the script.
[filename, filedir] = uigetfile('*.xlsx','MultiSelect','off');
filepath = fullfile(filedir,filename);
data = xlsread(filepath,'A1:B2');
It works the same way with .csv files, just change the '*.xlsx' to '*.csv' and read command to csvread().

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!