Using while loop to analyze lines repeated
조회 수: 2 (최근 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에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!