Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Paige Nardozzo
Paige Nardozzo le 8 Déc 2015
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Paige Nardozzo
Paige Nardozzo le 8 Déc 2015
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 le 8 Déc 2015
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.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by