readtable failing on MATLAB documentation example
Mostra commenti meno recenti
I am trying to perform a read of a simple CSV file. When my code did not work, I decided to run the exact example provided in the MATLAB documentation. I get the exact same cryptic error message. Otherwise MATLAB seems to be working perfectly.
Matlab example .csv data, I placed in "test.txt" (I also tried with "test.csv")
LastName,Gender,Age,Height,Weight,Smoker
Smith,M,38,71,176,1
Johnson,M,43,69,163,0
Williams,F,38,64,131,0
Jones,F,40,67,133,0
Brown,F,49,64,119,0
commands run after a "clear all"
filename = "test.txt"
T = readtable(filename);
resulting MATLAB error message:
Error using readtable (line 216)
REPLACE: "what" and "by" matrices incompatible
Note: readtable detected the following parameters:
'Delimiter', ',', 'HeaderLines', 0, 'ReadVariableNames', true, 'Format', ''
I traced execution through the MATLAB's readtable.m and subsquent calls and verified that the file is opening, the header line is read, and initially the "guessed format" appears correct. After determining the data format, MATLAB raises an exception at the next higher step in the call hierarchy. I've tried quite a few variations with and without various function options/arguments.
Any idea what I am doing wrong?
5 Commenti
dpb
il 17 Dic 2020
Which release and is this new installation or upgrade? Has readtable ever worked properly with this install?
Can't reproduce symptom here--
>> filename = fullfile(matlabroot,'examples','matlab','myCsvTable.dat');
>> readtable(filename)
ans =
5×6 table
LastName Gender Age Height Weight Smoker
____________ ______ ___ ______ ______ ______
{'Smith' } {'M'} 38 71 176 1
{'Johnson' } {'M'} 43 69 163 0
{'Williams'} {'F'} 38 64 131 0
{'Jones' } {'F'} 40 67 133 0
{'Brown' } {'F'} 49 64 119 0
>>
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.7.0.1261785 (R2019b) Update 3
...
Steven Lord
il 17 Dic 2020
Let's make sure you're using the readtable function included in MATLAB. What does this command display?
which -all readtable
Brad Fennell
il 17 Dic 2020
Image Analyst
il 17 Dic 2020
Mine shows
>> which -all readtable
C:\Program Files\MATLAB\R2020b\toolbox\matlab\iofun\readtable.m
C:\Program Files\MATLAB\R2020b\toolbox\shared\io\general\+matlab\+io\@ImportOptions\ImportOptions.m % matlab.io.ImportOptions method
Can you upgrade to the newest version? why stay stuck on a 2 year old version?
dpb
il 18 Dic 2020
That's what R2019b shows; R2017b shows the one file; I don't have R2018b installed to check.
OP could also check to see if are updates to the release he has installed.
Risposte (3)
Brad Fennell
il 17 Dic 2020
1 Commento
dpb
il 17 Dic 2020
As Steven L, suggests, show us what
which -all readtable
shows and we still don't know which release you're running, either.
Brad Fennell
il 17 Dic 2020
0 voti
Brad Fennell
il 17 Dic 2020
Modificato: Cris LaPierre
il 18 Giu 2021
0 voti
Categorie
Scopri di più su Introduction to Installation and Licensing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!