Create a subclass in subfolder

2 Ansichten (letzte 30 Tage)
Björn Persson
Björn Persson am 19 Mär. 2021
Kommentiert: Björn Persson am 19 Mär. 2021
Hi,
I want to make a subclass in a subfolder.
I have the main folder with main_class.m (working directory)
In this folder i want to create many subfolders with many different subclasses. How is this done?
I need to specify that the subclass should inherit from a superclass in parent directory. Plain like this does not work:
classdef sub_class < main_class
%instrObj creates an instrument object
properties
Property1
end
methods
function obj = untitled(inputArg1,inputArg2)
%UNTITLED Construct an instance of this class
% Detailed explanation goes here
obj.Property1 = inputArg1 + inputArg2;
end
function outputArg = method1(obj,inputArg)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
outputArg = obj.Property1 + inputArg;
end
end
end
Thanks.

Akzeptierte Antwort

Matt J
Matt J am 19 Mär. 2021
Bearbeitet: Matt J am 19 Mär. 2021
If all the classes and sub-classes are completely contained in their own classdef mfiles, then it doesn't matter where within your folder tree you put the classdef files, as long as they are all visible to Matlab, i.e., all branches of the tree are on the Matlab path.
If you are using Class Folders, however, the sub-class @-folders cannot be sub-folders of the parent class @-folders. But that is the only restriction.
  1 Kommentar
Björn Persson
Björn Persson am 19 Mär. 2021
Yes. Now it works. I struggled several hours with this yesterday and after your feedback I just tried the same thing again and it works. Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by