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

7 ビュー (過去 30 日間)
Bhowmik.U
Bhowmik.U 2019 年 4 月 15 日
コメント済み: Bhowmik.U 2019 年 4 月 18 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by