unable to detect a class file to instantiate object

10 vues (au cours des 30 derniers jours)
Udaykaran Madaan
Udaykaran Madaan le 26 Mai 2023
Réponse apportée : Swaraj le 29 Mai 2023
My file structure is like this
+LLSPP
TMS_2023.m
trial.m
some other files..
in 'trial.m' I have a class definition with a constructor
I am using this in TMS_2023.m
import LLSPP.*
and later trying to instantiate the class
T1 = LLSPP.trial(input1, input2)
but I keep getting this :
Unable to resolve the name 'LLSPP.trial'.
I also tried
T1 = LLSPP.trial.trial(input1, input2)
and
T1 = trial.trial(input1, input2)
and
T1 = trial(input1, input2)
they give the same error

Réponses (1)

Swaraj
Swaraj le 29 Mai 2023
Hi Udaykaran,
I understand that you are not able to access the constructor/class from a script written in the same package. I tried to regenerate the issue. I created the following file structure.
The content of the files are as follows:
File : trial.m
classdef trial
properties
Value;
end
methods
function obj = trial(input1,input2)
obj.Value = input1+input2;
end
end
end
File : TMS_2023.m
import LLSPP.*
LLSPP.trial(10,10);
On running the script “TMS_2023.m”, I was able to access the constructor.
The steps that you followed should work fine. Please try the following steps because of which you might face this error.
  1. To make sure that MATLAB is loading the class correctly you can run the command in the command window: clear classes
  2. Note that LLSPP needs to be on your MATLAB search path, or the full path to LLSPP.trial should be specified.
If the above steps do not help, please check if you have written the “trial” class properly. Go through the following documentation for reference.
Hope it helps!!.

Catégories

En savoir plus sur Construct and Work with Object Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by