CSV readtable dosen't work
11 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2023 年 8 月 11 日
F = '02.08.23_15.54.32_RTCM_STA8100_D0_stgsa.csv';
T = readtable(F, 'Delimiter',',', 'ExpectedNumVariables',26, 'VariableNamesLine',1)
採用された回答
Star Strider
2023 年 8 月 9 日
Perhaps something like this —
T1 = cell2table(compose('%f',randn(5,7)))
VN = T1.Properties.VariableNames;
T2 = varfun(@str2double,T1);
T2.Properties.VariableNames = VN
.
2 件のコメント
Star Strider
2023 年 8 月 10 日
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.
.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!