フィルターのクリア

How to go one line before in a while loop ?

7 ビュー (過去 30 日間)
NoNo
NoNo 2015 年 11 月 11 日
コメント済み: NoNo 2015 年 11 月 11 日
Hello everyone,
I wonder if we can go back one line before during a while loop? Here is the code to understand better my question:
while ~feof(fileID)
tline = fgetl(fileID);
if (isempty(tline))
else
if ischar(tline)
U = regexp(tline, ',ChipId,');
if isfinite(U) == 1;
A=strsplit(tline,',');
ChipID1.id=A{1};
% here I want to go one line before in my file that I read and collect the information of the previous line
B = strsplit("tline-1",',') % I know that I cannot write tline-1 to obtain what I want but this is the spirit
ChipID2.id= B{1};
end
I know that tline is not a number of line and I cannot write "tline-1" to go back to previous line but how can I do it ???
Thank you very much for your help !!!
N0N0

回答 (1 件)

Thorsten
Thorsten 2015 年 11 月 11 日
Store the line before and use it if needed:
tline = [];
while ~feof(fileID)
linebefore = tline;
tline = fgetl(fileID);
  1 件のコメント
NoNo
NoNo 2015 年 11 月 11 日
Thank you very much :)

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

カテゴリ

Help Center および File ExchangeSwitches and Breakers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by