Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Problem with fileread when used in the code but when used all by itself it works. Why?

조회 수: 1 (최근 30일)
Hi,
I have an output file that I am trying to read and scan for a certain phrase. If that phrase is in the output file then the loop in my code can continue. If not I want to terminate it. The phrase is 'TWOPNT: SUCCESS'. This is the code I have as of now:
Pattern = 'TWOPNT: SUCCESS'
A = fileread('OppDiff_HTPB_N2O.out')
B = strfind(A,Pattern)
empty = [] %what B will spit out an empty matrix if the pattern is not
%found in the file
if isequal(size(empty), size(B))
disp('No TWOPNT success found...may be a convergence problem')
error_message = 'No TWOPNT: SUCCESS found'
break
else %if the B matrix is not empty
disp('TWOPNT appears to have been successful! Conitnuing...')
endif
I made this part of my code and ran it by itself and it worked fine. However when I went to input it into my overall code it gets to this section and it goes to the fileread and spits out A=>> and stops working. Is there a certain size limit? If so why did it work when I used it outside of the code but not in it? Thanks.
  댓글 수: 2
Paige Nardozzo
Paige Nardozzo 2015년 12월 8일
Sorry this is the code
Pattern = 'TWOPNT: SUCCESS'
A = fileread('OppDiff_HTPB_N2O.out')
B = strfind(A,Pattern)
empty = [] %what B will spit out an empty matrix if the pattern is not
%found in the file
if isequal(size(empty), size(B))
disp('No TWOPNT success found...may be a convergence problem')
error_message = 'No TWOPNT: SUCCESS found'
break
else %if the B matrix is not empty
disp('TWOPNT appears to have been successful! Conitnuing...')
endif
Paige Nardozzo
Paige Nardozzo 2015년 12월 8일
I made this part of my code and ran it by itself and it worked fine. However when I went to input it into my overall code it gets to this section and it goes to the fileread and spits out A=>> and stops working. Is there a certain size limit? If so why did it work when I used it outside of the code but not in it? Thanks.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by