MATLAB: How to get rid of empty space and unit in the output

text file

Hello,
I have created a little code that opens 1×1 table(can not change the form in the .txt file) and stores a particular value. However the output is adding on the white spaces and [km]. How do I get rid of that? I just want the number to appear.
Here is my code:
filename = ('C:\Users\creid\Desktop\STK_doc.txt')
opt = detectImportOptions(filename)
A = readtable(filename, opt)
X = A(38,2)
and here is the output:
'-712.419553 [km]'
I have also uploaded a snippet of the txt file

Best Answer

The following will parse your example file correctly for me:
A = readtable('example.txt', ...
'Format', '%s%f%s', ...
'Delimiter', {'\t', ' ', '=', '[', ']'}, ...
'MultipleDelimsAsOne', true, ...
'HeaderLines', 6, ...
'ReadVariableNames', false)
Related Question