Errorhandling with Readmatrix trying to read data from a file
Afficher commentaires plus anciens
I am using the "readmatrix" function in a matlab function in simulink to repeatedly read data out of a file called output.dat.
This works, but sometimes another Software is accessing the file for a quick moment so im getting a error message that states that permission to open the file is denied.
Is it possible to handle errors by editing the try catch part in the "readmatrix.m" directly? I want the function to try to access the file and in case it is not accessible then it should try again until it is accessable. How can i implement this best?
Thanks in advance.
5 commentaires
dpb
le 27 Juil 2022
With try...catch on the call to readmatrix is probably workable -- don't even think about trying to mung on the original.
Ideal would be some way to set up a semaphore with the other app, but that's probably going to get very involved -- I "know nuthink!" about Simulink but adding it as another layer besides can't make it easier...
Dennis G
le 4 Août 2022
Damien Pecher
le 17 Août 2023
Hey Dennis,
Did you solve your issue in the meantime?
I'm facing the exact same problem and looking for a sollution...
Thanks.
Dennis G
le 17 Août 2023
Damien Pecher
le 17 Août 2023
Thanks for the tips! I will try this in my code.
Réponses (1)
Rishav
le 7 Sep 2023
Hi Dennis,
I am glad that your issue is resolved.
Apparently, the file that you want to read was not occupied by the other software and you used "fopen" for the same:
open = fopen('output.dat','r');
If open is -1, then it's occupied and try running the loop again until the value is not -1 anymore.
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!