read a .txt file

2 次查看(过去 30 天)
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

采纳的回答

Mathieu NOE
Mathieu NOE 2021-9-10
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]}

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by