loop while as much has first file
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone, I'm new at this so please bear with me :)
I have a function where it reads two files using another function which has a while inside that loops depending on the size of the file. Example: [MY function] record1 = read_file(fname1); record2 = read_file(fname2);
I need to make it so that the second file will only loop has much has the first did.
Is there any way to do this?
I'll await your suggestions ;)
댓글 수: 1
Preethi
2016년 11월 28일
hi,
you can add one more input argument and an output argument which will indicate the count.
답변 (3개)
KSSV
2016년 11월 28일
You put both the files read_file(fname1) and read_file(fname2) under the same loop/ under the same condition. Then obviously both the files run for the same time.
댓글 수: 0
Preethi
2016년 11월 28일
hi,
hope this helps
cnt=0;
[record1,cnt_op1] = read_file(fname1,cnt);
[record2,cnt_op2] = read_file(fname2,cnt_op1);
inside the function check second argument value, if its zero run till EOF else run till the length mentioned in second input argument. save the length of file (or while loop count)in output argument so that the same value can be passed as input next time.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!