フィルターのクリア

Reading in text file using textscan.

146 ビュー (過去 30 日間)
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 8 日
コメント済み: Andrew Czeizler 2019 年 3 月 11 日
Hi All, I need to read a text file into four row vectors named bottleID, date, ph and pressure using textscan.
The file has the following format -
I have made an attempt but I am finding the function textscan quite difficult to use.
My attempt is below -
fileID = fopen('hots_data.txt','r');
format_string = '%n %[{dd-MMM-yyyy}D]%q %d %d';
C = textscan(fileID, format_string, 'delimiter', ' ', 'whitespace', ' ');
fclose(fileID);
Any help would be very much appreciated.
Many thanks,
Best,
Andrew
  6 件のコメント
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 8 日
I have uploaded the file. Tried a loop technique with no success ......
Totally lost on this one.
Best,
Andrew
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 10 日
編集済み: Andrew Czeizler 2019 年 3 月 10 日
Hi All,
I was able to get textscan to work, but I cant read it into rows?
Is there a method that I am missing?
Best.
Andrew
fileID = fopen('testdata1.txt','r');
C = textscan(fileID, '%d %{dd-MMM-yyyy}D %f %f', 'Delimiter', ' ');
fclose(fileID);

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

採用された回答

Stephen23
Stephen23 2019 年 3 月 10 日
編集済み: Stephen23 2019 年 3 月 11 日
textscan imports file data into one cell array, the contents of which are one or more arrays (numeric, cell, datetime, etc), where their number of rows depends on the rows imported from the file and their columns depends on the format specifier and options that you used.
textscan does not import into separate variables, or transpose imported data.
"I need to read a text file into four row vectors named bottleID, date, ph and pressure using textscan."
[fid,msg] = fopen('testdata1.txt','rt');
assert(fid>=3,msg)
C = textscan(fid, '%d%{dd-MMM-yyyy}D%f%f', 'Delimiter',' ');
fclose(fid);
bottleID = C{1}.';
date = C{2}.';
ph = C{3}.';
pressure = C{4}.';
  1 件のコメント
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 11 日
Thank you Stephen! Legend!
I understand the concepts.
Best,
Andrew

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

その他の回答 (1 件)

KSSV
KSSV 2019 年 3 月 8 日
Read about readtable.
T = readtable(myfile) ;
  1 件のコメント
Stephen23
Stephen23 2019 年 3 月 8 日
Andrew Czeizler's "Answer" moved here:
Thank you for your help. The question has requested that I use textscan.
Many thanks,
Best,
Andrew

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by