CSV readtable dosen't work
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dominik Coenen
el 9 de Ag. de 2023
Comentada: Dominik Coenen
el 11 de Ag. de 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 comentarios
Stephen23
el 11 de Ag. de 2023
F = '02.08.23_15.54.32_RTCM_STA8100_D0_stgsa.csv';
T = readtable(F, 'Delimiter',',', 'ExpectedNumVariables',26, 'VariableNamesLine',1)
Respuesta aceptada
Star Strider
el 9 de Ag. de 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 comentarios
Star Strider
el 10 de Ag. de 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.
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Variables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!