Errorhandling with Readmatrix trying to read data from a file

조회 수: 9 (최근 30일)
Dennis G
Dennis G 2022년 7월 27일
답변: Rishav 2023년 9월 7일
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
Dennis G
Dennis G 2023년 8월 17일
Hello Damien,
yes i solved the issue. I did errorhandling differently: First i made sure that the file i want to read in is actually not occupied by the other software. This i did by using "fopen":
open=fopen('output.dat', 'r');
If open is -1 then it is occupied and i will just try again (loop) until the value is not -1 anymore.
Another thing i did was checking open for "integrity", so i checked if it contains the array i expect in the expected format (for example with "if open =~ isequal(size(output), [6 2])...).
This helped.
Damien Pecher
Damien Pecher 2023년 8월 17일
Thanks for the tips! I will try this in my code.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rishav
Rishav 2023년 9월 7일
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.

카테고리

Help CenterFile Exchange에서 Naming Conventions에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by