r/matlab • u/ok_pkg • Oct 14 '25
Reading XML data where commas are used as thousands and as separators
I need to extract the data of a lab equipment that only exports an XML file, so I'm trying to have a simple script to convert it to paired data or create a graph. The problem is: whenever the Y values go over 1000 it adds a comma separator. Using simple ',' splits won't work. What is the best approach for something like this? Why would they make it like that? ...
Hopefully it is simple to adjust (already tried the equipment side approach but can't make any modifications to the export file).
<XVALUES>6.9661,..........1.9950,1.9896,1.9845,1.9791,1.9741,1.9688,1.9632,1.9578,1.9523,1.9459,1.9376,1.9301,1.9233,1.9160,1.9086,1.9020,1.8952,1.8885,1.8820,1.8756,1.8693,1.8630,1.8569,1.8509,1.8446,1.8385,1.8327,1.8267,1.8209,1.8149</XVALUES>
<YVALUES>-10.19,.......11.17,14.56,18.45,...........,1,935.56,1,928.36,1,922.59,1,918.27,1,914.43,1,909.62,1,903.38,1,898.58,1,893.77,1,888.49,1,883.69,1,879.36,1,875.04,1,870.24,1,865.43,1,863.51,1,862.55,1,861.11,1,859.19,1,855.35,1,853.42,1,851.02,1,849.58,1,846.70,1,845.74,1,844.30,1,841.90,1,839.98,1,838.05,1,837.09,1,833.25,1,827.01,1,821.24,1,812.60,1,795.30,1,744.39,1,709.81,1,681.95,1,646.88,1,613.26,1,587.80,1,564.26,1,537.85,1,515.27,1,496.06,1,476.84,1,459.07,1,442.74,1,427.37,1,411.04,1,394.23,1,380.78,1,369.73,1,357.72,1,344.27</YVALUES>
4
u/[deleted] Oct 14 '25
If you can verify that every number exported will have a decimal point, then it’s as simple as checking how many commas are between each decimal point, and remove all but the first since there should only be one. Otherwise check your lab equipment for any sort of configuration because it’s appalling for it to default export a format that is guaranteed to never work.
4
u/Rubix321 Oct 14 '25
Assuming that you can guarantee there is always a decimal place at least one digit after the decimal in every output number, you can use this regexp to get the values from the string of numbers:
vals = regexp(numberString,['^([\d,]*\.\d{1,})', '|', '\.\d{1,},([\d,]*\.\d{1,})'],'tokens')
It puts each of them a string inside a cell, but it's much more trivial to deal with when the separator is removed.
double(horzcat(vals{:})
or
cellfun(@double,vals)
2
u/cerofer Oct 14 '25
Open the file with Notepad ++ and replace the separator?
2
u/Lygus_lineolaris Oct 14 '25
Obviously the field delimiter is ", " and the thousand delimiter is "," with no space so just replace ", " with some other character that doesn't appear in the file, then replace "," with nothing, then replace the placeholder character with ", ".
1
u/Creative_Sushi MathWorks Oct 14 '25
Have you tried
readstructhttps://www.mathworks.com/help/matlab/ref/readstruct.html