Matlab fail to read csv data with csvread()

I tried using csvread() function to read a csv file to get the data, which is in the same folder as the script.
M = csvread('JumperDataWin_Fixed.csv');
But I got these errors
Error using dlmread (line 122)
The file 'JumperDataWin_Fixed.csv' could not be opened because: Invalid argument
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
Error in LAB1 (line 8)
M = csvread('JumperDataWin_Fixed.csv');
Could anyone explain what's wrong with my codes?
Thanks!
Updated: attach the file

댓글 수: 11

Geoff Hayes
Geoff Hayes 2019년 2월 1일
kairui - is JumperDataWin_Fixed.csv a genuine CSV file or is it in some other format with a csv extension? Can you attach the file to this question?
kairui wang
kairui wang 2019년 2월 1일
Yes. Thanks for reminding.
I am able to open that file using your line of code
M = csvread('JumperDataWin_Fixed.csv');
although I am using R2014a on a Mac...which version and OS are you using?
kairui wang
kairui wang 2019년 2월 1일
Mine are R2018a and Windows
Is it possible that there is some hidden character in the filename in your code? Try using
dinfo = dir('Ju*.csv');
filenames = {dinfo.name};
and examine filenames, and if you find one that looks right (say the third),
[fid, message] = fopen(filenames{3})
and see if that works.
If it still fails with invalid argument, try copying and pasting the content into a different file, under the theory that something is corrupted in the metadata of the file.
Question: would you just happen to be trying to read this file from OneDrive with Windows 10 Spring (2018) Update ? Or from a networked drive of some other kind?
Geoff Hayes
Geoff Hayes 2019년 2월 1일
편집: Geoff Hayes 2019년 2월 1일
Try putting a break point at line 48 of csvread.m and then try your code again. Since the error message is saying something like "invalid argument", what are the filename, r, and c of
m=dlmread(filename, ',', r, c);
Mr. Roberson, I tried executing
dinfo = dir('JumperDataWin_Fixed.csv');
filenames = {dinfo.name};
But it seems return nothingCapture.PNG
I don't read this file from OneDrive, it's in my computer.
BTW, I tried the same syntax in computers of my school. It worked. It seemed to be the issue of my laptop.
kairui wang
kairui wang 2019년 2월 1일
Mr. Hayes, I set the point in Line48 in csvread, when it halted there, everything is okay, but when it ran through all the codes, the errors appeared.
kairui - is the file in the MATLAB Search Path? Prepend the full path to the file in your call to csvread, like
M = csvread('C:\somePath\JumperDataWin_Fixed.csv');
What shows up if you use
ls
? Perhaps there is not an exact match for the file name.
kairui wang
kairui wang 2019년 2월 1일
I solved it. The reason is that there're some strange symbols in the the name of folder which contains the data. Matlab can't recognize the symbol so it generate a random symbol to replace it. Thank you guys!

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

질문:

2019년 2월 1일

댓글:

2019년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by