Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Matlab OOP and Warndlg Crashing Matlab

1 Ansicht (letzte 30 Tage)
abhay  kaul
abhay kaul am 5 Apr. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I have recently started using OOP in Matlab. I have defined a class "ReadFile" that accepts a file name via a constructor class. The class has a dependent variable "file". The get method for the variable "file" is defined by calling an external function. The external function has some error check logic which uses "warndlg" to display error.
Here is the class:
classdef ReadFile
properties
% some vars
fileName;
end
properties(dependent=true)
file;
end
methods
% constructor class
function obj=ReadFile(fileName)
obj.fileName = fileName;
end
% get method for dependent
function fileInfo=get.file(obj)
fileInfo = ExternalFunc(obj.fileName);
end
end
The ExternalFunc is a file read function that displays an warning dialogue if the file cannot be opened and it outputs an empty variable in place of fileInfo.
The main script looks like this:
read = ReadFile('myFile.txt');
data = read.file
This creates two variables in the workspace: "read" class and "data". If I input the incorrect file name then the class as expected displays the warndlg but if I try to open the "read" class from the workspace it again reopens the warndlg and keeps on opening it over and over. I can't stop execution hence I have to terminate the Matlab session. I am trying to investigate the root cause. I suspect given that I am new to OOP in Matlab, I am missing something basic.
I would appreciate any suggestions.
Thanks! Abhay
  2 Kommentare
Geoff Hayes
Geoff Hayes am 5 Apr. 2015
Abhay - please clarify what you mean by try to open the "read" class from the workspace it again. What are you trying to open - the read instance or the file that read references?
abhay  kaul
abhay kaul am 5 Apr. 2015
Bearbeitet: abhay kaul am 5 Apr. 2015
Geoff,
read = ReadFile('myFile.txt');
creates a variable "read" in the workspace. Please see the screenshot (my actual class is named as ReadTMPFile instead of ReadFile in the example code above). I am trying to open this class variable/instance from workspace and this keeps on throwing the warndlg over and over. It seems that opening this instance from the workspace iteratively calls the class if there is warndlg.
If I remove warndlg from the external function and simply display error in the command window in case of a failure, opening of the "read" does not cause this issue.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by