フィルターのクリア

reading text file with multiple rows and columns

11 ビュー (過去 30 日間)
Anjali Acharya
Anjali Acharya 2019 年 2 月 28 日
回答済み: yosun yapar 2019 年 5 月 25 日
How can i read my text file which has 2-3 lines of unwanted message and then reading of data in this format:
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2019.02.26 16:14:15 =~=~=~=~=~=~=~=~=~=~=~=
AS7263 online!
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[7.27] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[8.31] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[8.31] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[8.31] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[8.31] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[7.27] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[7.27] W[8.66] tempF[93.2]
Reading: R[7.39] S[7.65] T[8.28] U[9.98] V[7.27] W[8.66] tempF[93.2]
I want to extract labels like R,S,T,U,V,W,temp and their respective values.
  2 件のコメント
Stephan
Stephan 2019 年 2 月 28 日
Mabe it will help if you attach a sample file
Anjali Acharya
Anjali Acharya 2019 年 2 月 28 日
Hey Stephan here is my sample file.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 2 月 28 日
z = fopen('now1.txt'); c = textscan(z,'%s','delimiter','\n'); fclose(z);
t = regexp(c{:}{3},'\w*(?=\[)','match');
n = regexp(c{:},'(?<=\[)\d+\.\d+(?=\])','match');
out = array2table(str2double(cat(1,n{:})),'V',t);
Here now1.txt - text file with your data.
  2 件のコメント
Anjali Acharya
Anjali Acharya 2019 年 2 月 28 日
Hello Andrei ,
it works ,thank you
Anjali Acharya
Anjali Acharya 2019 年 2 月 28 日
Hello Andrei,
For now i have single text file but in future if i take reading for my experiment sample, there will be 100 files inside a folder. Then I will need to loop through each text file and create seperate table for each file.
Is it possible to do this?

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

その他の回答 (1 件)

yosun yapar
yosun yapar 2019 年 5 月 25 日
Hi,
when a file contains both a space, and a comma-separated and none value data as appendix,
solutionestimate = textscan(fid,'%s %s %f %s %s %s %s %s %s %f %f %f %f %f %f %f ' ...
, 'Delimiter', {' ',','} , 'MultipleDelimsAsOne', true,);
output does not work correctly. How can I solve this?

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by