Info

This question is closed. Reopen it to edit or answer.

How can I use a txt file as input of a table?

1 view (last 30 days)
Georgios
Georgios on 29 Oct 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi, I have the attached .txt file and I want to use it as input in MATLAB. I want to create a 10x5 table using Time, Az, El, Range and Footp as variables.

Answers (1)

Cedric
Cedric on 29 Oct 2013
Edited: Cedric on 29 Oct 2013
It is not trivial because there is a header and the decimal delimiter is the comma. If you need a numeric time stamp (suited for plotting) and numeric data, you can do it as follows:
% - Read data, replace comma with point as decimal sep., scan columns.
raw = fileread( 'SAT.txt' ) ;
raw = strrep( raw, ',', '.' ) ;
data = textscan( raw, '%s %s %f %f %f %f', 'HeaderLines', 4 ) ;
% - Aggregate to string time stamp and convert to numeric.
timeStamp_str = arrayfun(@(r) [data{1}{r}, ' ', data{2}{r}], ...
1:numel(data{1}), 'UniformOutput', false ) ;
timeStamp_num = datenum( timeStamp_str ) ;
% - Aggregate data into num array.
data = [data{3:end}] ;
Note that you can use timeStamp_str as labels for plot axes.

Community Treasure Hunt

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

Start Hunting!