フィルターのクリア

How can i access one cell {1x1} to split/separate its contained value?

1 回表示 (過去 30 日間)
ARN
ARN 2018 年 8 月 17 日
編集済み: Stephen23 2018 年 8 月 17 日
I have a .txt file , which contains data like follows
----------------Wed Aug 15 09:30:26 2018Wed Aug 15 09:30:26 2018Wed Aug 15 09:30:26 2018Wed Aug 15 09:30:26 2018----------------Wed Aug 15 09:30:28 2018Wed Aug 15 09:30:28 2018Wed Aug 15 09:30:28 2018Wed Aug 15 09:30:28 2018
I want to separate/split this data in following manner:
-------- (break)
-------- (break)
Wed Aug 15 09:30:26 2018 (break)
Wed Aug 15 09:30:26 2018 (break)
Wed Aug 15 09:30:26 2018(break)
Wed Aug 15 09:30:26 2018(break)
--------(break)
--------(break)
Wed Aug 15 09:30:28 2018(break)
Wed Aug 15 09:30:28 2018(break)
Wed Aug 15 09:30:28 2018(break)
Wed Aug 15 09:30:28 2018(break)
if I call/access that .txt file with fopen and fgets or importdata, all the data get stored in one cell {1x1}.How can i access this one cell to split/separate in shown manner?
P.S: Break means space or starting a new line
  1 件のコメント
Stephen23
Stephen23 2018 年 8 月 17 日
@Ahmad Riaz Nayer: please upload your data file by clicking the paperclip button.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 8 月 17 日
編集済み: Stephen23 2018 年 8 月 17 日
Here is a simple solution using regexprep:
>> str = fileread('test.txt');
>> regexprep(str,'(-{8}|\d{4})','$1\n')
ans = --------
--------
Wed Aug 15 09:30:26 2018
Wed Aug 15 09:30:26 2018
Wed Aug 15 09:30:26 2018
Wed Aug 15 09:30:26 2018
--------
--------
Wed Aug 15 09:30:28 2018
Wed Aug 15 09:30:28 2018
Wed Aug 15 09:30:28 2018
Wed Aug 15 09:30:28 2018
The test file is attached (you did not provide any sample file).
  2 件のコメント
ARN
ARN 2018 年 8 月 17 日
Thanks for the answer. One more thing, Its still in one cell {1x1} while i want to have the separated data in new cell or stored in one new matrix. So for your test.txt file it should make 1x12 cell/matrix. Thanks
Stephen23
Stephen23 2018 年 8 月 17 日
編集済み: Stephen23 2018 年 8 月 17 日
@Ahmad Riaz Nayer: your original question indicated that you wanted line breaks, so that is what I inserted into the string. If you want to split the string into multiple strings, then try regexp:
>> str = fileread('test.txt');
>> C = regexp(str,'(-{8}|[\w :]+?\d{4})','match');
>> C{:}
ans = --------
ans = --------
ans = Wed Aug 15 09:30:26 2018
ans = Wed Aug 15 09:30:26 2018
ans = Wed Aug 15 09:30:26 2018
ans = Wed Aug 15 09:30:26 2018
ans = --------
ans = --------
ans = Wed Aug 15 09:30:28 2018
ans = Wed Aug 15 09:30:28 2018
ans = Wed Aug 15 09:30:28 2018
ans = Wed Aug 15 09:30:28 2018

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by