Using while loop to analyze lines repeated
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, everybody. I have a doubt:
How can I compare three of the 7 columns in a file? I have a data file with 7 columns.
data = load('/home/pink/input.txt');
filenames = compose('precipi_%05d_%08d_%04d.dat', data(:,7), data(:,1), data(:,2));
nfiles = numel(filenames);
for K = 1:nfiles;
thisfile = filenames(K);
fileID = fopen(thisfile{1});
dados = fread(fileID,[500 500], 'float32');
dados((dados==-99.0))=NaN;
fclose(fileID);
end
However, I need to open each file only once, that is, the file precipi_02000_20140101_0000.dat, for example, can only be opened once. So I thought of doing an if / else for this. If the second line is the same as the first, considering column 1, 2 and 7, skip to the third line. If the third line is different from the previous one, the file will be opened. Then in this case the files will be opened twice considering the part of the file exposed above:
precipi_02000_20140101_0000.dat
precipi_03000_20140101_0000.dat
precipi_04000_20140101_0000.dat
I'm trying to do:
while ymd (K) == ymd (K==K+1);
K = K+1;
end
K = K-1;
where ymd is the first column (20140101), for example.
How to use while function to open each file only once?!
Thanks!
2 件のコメント
Geoff Hayes
2020 年 10 月 5 日
pink - you say If the third line is different from the previous one, the file will be opened. What do you mean bu this? Which file will be opened? Please clarify what you are comparing within each file.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Direct Search についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!