Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Paige Nardozzo
Paige Nardozzo 2015 年 12 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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