How to identify occurences in a text file and save both number and text into arrays

1 回表示 (過去 30 日間)
Hugo
Hugo 2022 年 5 月 3 日
コメント済み: Stephen23 2022 年 5 月 3 日
Hi,
I would like to open an external text file, with n lines and identify the lines which start with "VAR="
A typical line has "VARx=S", where x and S are integers. So, an example is VAR1=2
How can I save, for example:
Textarray=[VAR1,VAR2,VAR3,VAR4]
integerarrray=[2,4,6,7]
The code must be able to identify all the occurences where the line of the external text file starts with "VAR". The text above is just an example.
Right now, the code that I have only (attempts) to count the number of variables in my text file.
nvar=0
for i=1:1:nlines
fid = fopen('C:\code\a.txt','w');
k=strncmp(fid,'VAR',3)
if k==1
nvar=nvar+1
end
end
Any help is appreciated.
Thank you,

回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by