How do I separate a string with hyphen and colon separation within cell

2 次查看(过去 30 天)
When I am trying to read the file enclosed using the code below, the 1st and 2nd entries I am getting is an array of cells
with yyyy-mm-dd
and second with HH:MM:SS
I wish if there were any novel ways to get an array of cells separately with yyyy mm dd (without hyphen) and HH MM and SS (without :)
stated simply I wish I could have a work around to remove hyphen and colon and get each srting separate withing the cells.
Sorry if I sound gibberish!
code:
close all;
clear all;
fileID=fopen('RD-180531-160600.txt');
C=textscan(fileID,'%s%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%7.4f%7.4f%7.4f%[^\n]','HeaderLines',1);
fclose(fileID)
whos C

采纳的回答

Rik
Rik 2019-4-15
If you know the pattern you can simply use that to edit the FormatSpec:
fileID=fopen('RD-180531-160600.txt');
FormatSpec='%4s-%2s-%2s %2s:%2s:%2s %f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%7.4f%7.4f%7.4f%[^\n]';
C=textscan(fileID,FormatSpec,'HeaderLines',1);
fclose(fileID);
whos C

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by