Reading a file without extension

26 ビュー (過去 30 日間)
Chris Dan
Chris Dan 2022 年 4 月 28 日
編集済み: dpb 2022 年 4 月 28 日
Hello,
I want to read a file in matlab which doesnot have an extension. I am attaching the file by converting the file to .txt file because otherwise it cannot be uploaded, originally the file doesnot have any extension and I want to read it without extension. I am using this code
cd /hamzah/adda/src/seq/results/test/run002_cylinder_g25_m1.105;
A = importdata('log')
The problem is that I want to read this file from line 1 till line 21, but when i use import data, I could only read till line 2.
Does anyone knows how it can be solved?
  1 件のコメント
Stephen23
Stephen23 2022 年 4 月 28 日
編集済み: Stephen23 2022 年 4 月 28 日
Do not use CD to import/export data files. Using CD is slow and makes debugging harder.
All MATLAB functions that import/export data file data accept absolute/relative filenames.
Do not use PATH as a variable name (it is the name of an important function), use e.g. MYPATH.
Replace this:
[mypath '/' folders(k).name '/log']
with FULLFILE:
fullfile(mypath,folders(k).name,'log')

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

採用された回答

dpb
dpb 2022 年 4 月 28 日
編集済み: dpb 2022 年 4 月 28 日
Take @Stephen's comments to heart; they're important.
D='/hamzah/adda/src/seq/results/test/run002_cylinder_g25_m1.105';
txt=readlines(fullfile(D,'log.'));
will bring in the file content as a string array. As a freeform text file, the content is simply too irregular for any of the prepared file routines to be able to handle.
The other technique for such files where generally one is interested in parsing one or more specific pieces of information is to use low-level i/o and fgetl(() and then parse each line in turn.
There are a number of examples of such on the Answers forum; I don't have a specific link but I know I've written several...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by