CSV readtable dosen't work
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dominik Coenen
il 9 Ago 2023
Commentato: Dominik Coenen
il 11 Ago 2023
Hi there,
I am trying to read a CSV file with readtable. Readtable doesn't detect the correct datatype and detectImportOptions also dosen`t work either. I tried to convert the last columns to numbers with the following loop:
for i = 11:(width(stgsa_csv_table))
stgsa_csv_table{:,i} = str2double(stgsa_csv_table{:,i});
end
But it's not possible and following error message is displayed :
Error using {}
Conversion to cell from double is not possible.
Does anyone know how to solve this problem?
Thanks Dominik
4 Commenti
Stephen23
il 11 Ago 2023
F = '02.08.23_15.54.32_RTCM_STA8100_D0_stgsa.csv';
T = readtable(F, 'Delimiter',',', 'ExpectedNumVariables',26, 'VariableNamesLine',1)
Risposta accettata
Star Strider
il 9 Ago 2023
Perhaps something like this —
T1 = cell2table(compose('%f',randn(5,7)))
VN = T1.Properties.VariableNames;
T2 = varfun(@str2double,T1);
T2.Properties.VariableNames = VN
.
2 Commenti
Star Strider
il 10 Ago 2023
As always, my pleasure!
One approach (consistent with the current approach) —
T1 = cell2table(compose('%f',randn(5,7)));
T1.HexVar = {'8';'9';'A';'B';'C'}
VN = T1.Properties.VariableNames;
T1.HexVar = compose('%f',hex2dec(T1.HexVar))
T2 = varfun(@str2double,T1);
T2.Properties.VariableNames = VN
This requires knowing what variables are hex and specifically converting them to numeric first. The detectImportOptions documentation under Parameters for Text Files Only has HexType that governs how to convert it. I get the impression that the converstion to numeric is done automatically, although selecting 'text' woiuld prevent its conversion so it would be read into the table as text.
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Variables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!