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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Rik
Rik am 15 Apr. 2019
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

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by