Time reading in matlab

조회 수: 14 (최근 30일)
Silpa K
Silpa K 2019년 8월 23일
댓글: Silpa K 2019년 8월 24일
Hi, I have a data set, using matlab I need to read all the data.But the date and time reading is not working.Please help me.
  댓글 수: 8
Walter Roberson
Walter Roberson 2019년 8월 24일
Zip the file and attach the .zip here.
Silpa K
Silpa K 2019년 8월 24일
This is one of it

댓글을 달려면 로그인하십시오.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 8월 24일
Hi,
Here is the complete solution script. Please note that your data file is renamed (S1932.txt):
File_Name = 'S1932.txt';
Formatting_Spec = '%s%s%s %s%f%s %f%f%f %c %d%d%d';
N_header = 10;
My_FID=fopen(File_Name, 'r');
DATA=textscan(My_FID, Formatting_Spec, 'headerlines', N_header);
fclose(My_FID);
Date = DATA{1}; % You can ignore this
Time = DATA{2}; % You can ignore this
ET = DATA{3}; % You can ignore this
GT = DATA{4};
MAG = DATA{5};
M = DATA{6};
LAT = DATA{7};
LON = DATA{8};
DEPTH= DATA{9};
Q = DATA{10};
EVID = DATA{11};
NPH = DATA{12};
NGRM = DATA{13};
Good luck.
  댓글 수: 1
Silpa K
Silpa K 2019년 8월 24일
Thank you Sir.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 24일
%set up
opt = detectImportOptions('1932.catalog', 'FileType', 'text', 'readvariablenames', false, 'HeaderLines', 10);
opt = setvartype(opt, 1, 'datetime');
opt = setvaropts(opt,1,'InputFormat', 'yyyy/MM/dd');
opt.VariableNames = {'Date', 'Time', 'ET', 'GT', 'MAG', 'M', 'LAT', 'LON', 'DEPTH', 'Q', 'EVID', 'NPH', 'NGRM'};
%read the file
datatable = readtable('1932.catalog', opt);
%throw away the garbage last entries
datatable = rmmissing(datatable);
%create a composite date/time from the date and time fields
datatable.DateTime = datatable.Date + datatable.Time;
datatable.DateTime.Format = 'dd-MMM-uuuu HH:mm:ss.SSS';
  댓글 수: 1
Silpa K
Silpa K 2019년 8월 24일
Thank you sir .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by