writematrix with tab delimiter inconsistently producing delimiters

12 visualizaciones (últimos 30 días)
I'm writing a matrix to a .txt file using the following line of code:
writematrix(allCols,fullPath,'Delimiter','tab');
where allCols is a 53532x3 double. For some reason in the resulting .txt file, the tab delimiter is missing between the first and second columns for seemingly random rows and is instead replaced with a space. The only thing that seems to set the first column number in these rows apart is that the decimals end in 0, such that they only get written to 4 decimal places compared to the 5 that the other numbers are being written to. Is this a bug, or am I doing something wrong?

Respuesta aceptada

Star Strider
Star Strider el 5 de Ag. de 2024
It might be possible for you to verify whether the tab characters are ther or not using the funciton after creating the file.
Example —
format shortG
allCols = round(rand(8),5)
allCols = 8x8
0.64301 0.13506 0.34843 0.2491 0.18072 0.81414 0.6888 0.18641 0.04084 0.17259 0.2013 0.46789 0.10803 0.3105 0.02379 0.77418 0.59673 0.23764 0.19334 0.43903 0.14702 0.34452 0.69943 0.51894 0.96508 0.76131 0.44466 0.2378 0.34746 0.15956 0.23397 0.29093 0.93295 0.1832 0.72521 0.11602 0.12392 0.25467 0.12943 0.52008 0.57897 0.52007 0.9903 0.94986 0.64259 0.06571 0.66801 0.57649 0.78616 0.51758 0.4922 0.94905 0.93651 0.51614 0.83601 0.24031 0.81856 0.91521 0.13822 0.49348 0.28844 0.34432 0.17607 0.00767
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fullPath = 'test1.txt';
writematrix(allCols,fullPath,'Delimiter','tab');
A1 = readlines(fullPath)
A1 = 9x1 string array
"0.64301->0.13506->0.34843->0.2491->0.18072->0.81414->0.6888->0.18641" "0.04084->0.17259->0.2013->0.46789->0.10803->0.3105->0.02379->0.77418" "0.59673->0.23764->0.19334->0.43903->0.14702->0.34452->0.69943->0.51894" "0.96508->0.76131->0.44466->0.2378->0.34746->0.15956->0.23397->0.29093" "0.93295->0.1832->0.72521->0.11602->0.12392->0.25467->0.12943->0.52008" "0.57897->0.52007->0.9903->0.94986->0.64259->0.06571->0.66801->0.57649" "0.78616->0.51758->0.4922->0.94905->0.93651->0.51614->0.83601->0.24031" "0.81856->0.91521->0.13822->0.49348->0.28844->0.34432->0.17607->0.00767" ""
This appears to diaplay the tab characters as '->' although there does not appear to be anything in the readlines documentation describing how the various delimiters are displayed.
Contrast this with —
fullPath = 'test2.txt';
writematrix(allCols,fullPath,'Delimiter','space');
A2 = readlines(fullPath)
A2 = 9x1 string array
"0.64301 0.13506 0.34843 0.2491 0.18072 0.81414 0.6888 0.18641" "0.04084 0.17259 0.2013 0.46789 0.10803 0.3105 0.02379 0.77418" "0.59673 0.23764 0.19334 0.43903 0.14702 0.34452 0.69943 0.51894" "0.96508 0.76131 0.44466 0.2378 0.34746 0.15956 0.23397 0.29093" "0.93295 0.1832 0.72521 0.11602 0.12392 0.25467 0.12943 0.52008" "0.57897 0.52007 0.9903 0.94986 0.64259 0.06571 0.66801 0.57649" "0.78616 0.51758 0.4922 0.94905 0.93651 0.51614 0.83601 0.24031" "0.81856 0.91521 0.13822 0.49348 0.28844 0.34432 0.17607 0.00767" ""
.

Más respuestas (0)

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by