read a .txt file

2 ビュー (過去 30 日間)
Carmen Juliana Gonzalez
Carmen Juliana Gonzalez 2021 年 9 月 10 日
回答済み: Mathieu NOE 2021 年 9 月 10 日
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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by