CSVread / dlmread not working when trying to upload a CSV file

23 views (last 30 days)
Hi all,
I cannot upload my CSV file into matlab no matter what I try. I have attached both the CSV and Xlsx file and just want to upload the numbers. There are titles at the top of each column - I know that people keep saying it only likes numbers and not text but reading the documentation, from 2015 (I have 2019) you CAN have csv files with words in and can ignore them especially if they are on the top row.
I have tried every command I can, here are the main ones:
>> M = csvread('WPrimedatacsvtitle.csv',R1,C0) %meant to be skip out row one only
Undefined function or variable 'R1'.
Did you mean:
>> M = dlmread('WPrimedatacsvtitle.csv',',',R1,C1) %why not try C0 too
Undefined function or variable 'R1'.
any help would be greatly appreciated.

Accepted Answer

Stephen23
Stephen23 on 6 May 2020
Edited: Stephen23 on 6 May 2020
The csvread documentation explains that the 2nd, 3rd, 4th and 5th input arguments are an offset value, and that they must be specified as positive integers.
You have apparently tried to provide Excel-style cell references without any string qualifiers, which means they get interpreted as attempts to refer to some variables or functions of those names... which would be perfectly valid if you actually had variables or functions defined with those names. But as the error message makes quite clear, you don't.
In any case, it is simple to just provide integers, exactly as the documentation specifies:
M = csvread('WPrimedatacsvtitle.csv',1,0)
% ^ ^ integers
  3 Comments
Stephen23
Stephen23 on 12 May 2020
Edited: Stephen23 on 12 May 2020
It is not a CSV file is the standard meaning of the term: every line is surrounded by one pair of double quotes, thus indicating that every line should be interpreted as one string. The first few lines look like this:
"Name,Gender,Age,Mass,atime,btime,ctime,PPO,CP,Wprime"
"100,1,18,64.7,318,268,232,793,243,17040"
"101,2,19,58.3,415,361,325,911,295,21490"
"102,2,26,84.3,598,513,463,1497,418,32400"
I cannot imagine what kind of buggy application writes this and claims that it is a CSV file. The point of adding double quotes is to define a string (which might include delimiters), so this is a major design bug in that application, or whatever script was used to write it.
You basically have two choices:
  1. import the file into MATLAB as text, fiddle around with it, convert to numeric (e.g. textscan).
  2. remove the double quotes from the file to make it a proper CSV file (either by fixing the buggy tool that wrote it, or editing the file itself and replacing the double quotes). Then simply import using csvread or readtable. I would choose this option, it works fine:
>> M = csvread('WPrimedatacsvtitle.csv',1,0)
M =
1.0e+04 *
0.0100 0.0001 0.0018 0.0065 0.0318 0.0268 0.0232 0.0793 0.0243 1.7040
0.0101 0.0002 0.0019 0.0058 0.0415 0.0361 0.0325 0.0911 0.0295 2.1490
0.0102 0.0002 0.0026 0.0084 0.0598 0.0513 0.0463 0.1497 0.0418 3.2400
0.0103 0.0001 0.0020 0.0068 0.0362 0.0321 0.0277 0.0891 0.0249 2.0284
0.0104 0.0002 0.0021 0.0067 0.0466 0.0431 0.0394 0.1117 0.0351 2.0791
0.0105 0.0001 0.0021 0.0060 0.0352 0.0311 0.0288 0.0774 0.0267 1.5316
0.0106 0.0001 0.0027 0.0068 0.0322 0.0270 0.0226 0.1106 0.0194 2.3040
0.0107 0.0002 0.0026 0.0062 0.0424 0.0370 0.0326 0.1076 0.0299 2.2560
0.0108 0.0002 0.0020 0.0069 0.0439 0.0381 0.0336 0.1044 0.0302 2.4802
0.0109 0.0002 0.0018 0.0070 0.0412 0.0363 0.0319 0.1008 0.0288 2.2320
0.0110 0.0002 0.0020 0.0071 0.0417 0.0368 0.0320 0.1040 0.0345 2.3330
0.0111 0.0002 0.0018 0.0078 0.0532 0.0479 0.0441 0.1247 0.0371 2.9040
0.0112 0.0002 0.0025 0.0088 0.0491 0.0393 0.0340 0.1745 0.0290 3.6240
0.0113 0.0002 0.0024 0.0069 0.0481 0.0440 0.0393 0.0986 0.0364 2.1120
0.0114 0.0002 0.0028 0.0063 0.0322 0.0268 0.0221 0.1301 0.0187 2.4240
0.0115 0.0002 0.0023 0.0072 0.0551 0.0468 0.0421 0.1338 0.0378 3.1200
0.0116 0.0002 0.0025 0.0090 0.0462 0.0370 0.0322 0.1887 0.0275 3.3600
0.0117 0.0002 0.0018 0.0071 0.0442 0.0401 0.0359 0.1098 0.0331 1.9920
0.0118 0.0001 0.0019 0.0055 0.0300 0.0255 0.0224 0.0675 0.0199 1.8240
0.0119 0.0002 0.0020 0.0062 0.0427 0.0366 0.0330 0.0973 0.0297 2.3456
0.0120 0.0002 0.0022 0.0086 0.0549 0.0488 0.0407 0.1407 0.0360 3.4080
0.0121 0.0001 0.0024 0.0068 0.0254 0.0222 0.0195 0.0963 0.0175 1.4160
0.0122 0.0002 0.0019 0.0076 0.0433 0.0378 0.0337 0.1104 0.0346 2.3169
mehdi kordi
mehdi kordi on 12 May 2020
Right OK - thank you for clearing this up. It makes sense now - and have to go back to the developers.
Thanks again.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!