필터 지우기
필터 지우기

opening excel .csv

조회 수: 4 (최근 30일)
Dylan Mecca
Dylan Mecca 2018년 2월 7일
댓글: Bob Thompson 2018년 2월 7일
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
Bob Thompson
Bob Thompson 2018년 2월 7일
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().

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by