read a .txt file

조회 수: 4 (최근 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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by