why "writetable" replaces points with commas ???
조회 수: 19(최근 30일)
표시 이전 댓글
Hi
i have this array (12541x763),

and when i use writetable i will get this result

it replaces the points with commas, i wanted to keep the points instead of replacing them with commas,
this is the code I am using :
T = cell2table(DD);
writetable(T, 'myData.xlsx', 'WriteVariableNames', 0)
댓글 수: 3
Walter Roberson
2021년 7월 30일
this is a spreadsheet. It's writing out binary floating point.
No, it is xlsx, which is zip'd XML files. The numbers are represented as text.
tn = tempname() + ".xlsx"
SomeVar = [-29.7073; -29.7173734]
T = table(SomeVar)
writetable(T, tn)
cleanme = onCleanup(@() delete(tn));
[folder, filename, ext] = fileparts(tn)
outdir = fullfile(folder, filename);
unzip(tn, outdir)
cleanme2 = onCleanup(@() rmdir(outdir, 's'));
S = fileread(fullfile(outdir, 'xl', 'worksheets', 'sheet1.xml'));
regexprep(S, '>', '>\n')
Notice the text -29.7073 and the text -29.7173734
답변(2개)
Stephen23
2021년 7월 30일
편집: Stephen23
2021년 7월 30일
"why "writetable" replaces points with commas ???"
It doesn't.
The Open Office XML format (e.g. XLSX) uses only the decimal point within the XML files, regardless of the locale settings (and similarly all functions are actually stored in English, not in the language you might see displayed by Excel on your screen). WRITETABLE correctly creates the files according to the OOXML standard.
The comma you show in your second screenshot is purely an artifact of how the file is displayed in MS Office Excel according to the locale settings on your computer (tip: you can change the OS locale setting for the decimal radix character).
How MS Office Excel displays the decimal radix character has absolutely nothing to do with MATLAB.
댓글 수: 0
Jeremy Hughes
2021년 7월 30일
An XLSX file is a zip file containing XML data which is what the XLSX file is defined as. And as @Stephen Cobeldick points out, the text in the internal XML file is written out with "." as the decimal separator. (You can rename .xlsx files with .zip extenion and extract to see what's literally stored, but it's not easy to understand). Excel renders those number based on the local it sees fit.
If you call readtable on the created file, you're going to see the same numbers come back.
댓글 수: 2
참고 항목
범주
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!