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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Rik
Rik el 15 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by