read a .txt file

5 views (last 30 days)
Carmen Juliana Gonzalez
Carmen Juliana Gonzalez on 10 Sep 2021
Answered: Mathieu NOE on 10 Sep 2021
Hi,
I have a .txt file containing 6 columns of different data types separated by white spaces.
This is how the data of the .txt file looks like:
02/06/2021 10:54:08 Z 00009 z 00008
02/06/2021 10:54:08 Z 00009 z 00009
02/06/2021 10:54:08 Z 00009 z 00009
I made the following script, but it is not exactly what I need.
filename = '0-3000.txt';
fileID = fopen(filename,'r','n');
sprinIR_data = [];
sprinIR_data = textscan(fileID,'%{dd/MM/yyyy}D %{hh:mm:ss}T %s %f %s %d' );
What I need is to make a table with the second column (the time) and the 4th and 6th columns wich are the numerical values of the measurement.
I do not know how to manage the time type of data.
Thank you very much in advance for your help!
Kind regards,
Juliana

Accepted Answer

Mathieu NOE
Mathieu NOE on 10 Sep 2021
hello
have you tried to work with tables - using readtable ?
filename = '0-3000.txt';
T = readtable(filename);
C = table2cell(T);
gives :
T =
3×6 table
Var1 Var2 Var3 Var4 Var5 Var6
__________ ________ _____ ____ _____ ____
02/06/2021 10:54:08 {'Z'} 9 {'z'} 8
02/06/2021 10:54:08 {'Z'} 9 {'z'} 9
02/06/2021 10:54:08 {'Z'} 9 {'z'} 9
C =
3×6 cell array
{[02/06/2021]} {[10:54:08]} {'Z'} {[9]} {'z'} {[8]}
{[02/06/2021]} {[10:54:08]} {'Z'} {[9]} {'z'} {[9]}
{[02/06/2021]} {[10:54:08]} {'Z'} {[9]} {'z'} {[9]}

More Answers (0)

Categories

Find more on Tables 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!