How do I open a text file with fopen() in a local function, and return the file identifier to the parent script without MATLAB automatically closing the newly opened file?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to write my own "wrapper" for fopen(). Just like MATLAB's fopen() I would like to pass it a file name and return a valid file identifier that I can use to interrogate the data in the file. The problem is, if I open a file in my local function myfopen() MATLAB will automatically close it after finishing myfopen()'s execution. Can I instruct MATLAB to leave the file open and accessible to my parent script?
Thanks for any help,
- Guy
2 commentaires
dpb
le 2 Déc 2021
MATLAB never automagically closes a file opened with fopen unless somewhere you have either an explicit fclose on that file handle or use fclose('all')
We'd have to see the code outline and a minimum example that illustrates the problem you're seeing to diagnose the issue.
How do you come to the conclusion the file has been closed? More likely I would think is that you simply don't have the file handle in the current scope by having broken the chain of passing it from the initial function that did open the file.
Or, alternatively, do you exhaustively check that the fopen call actually succeeds and the file was ever opened? That would be another highly plausible way in which to (belatedly) discover the variable you're using is not a valid handle.
Réponses (0)
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!