Property assignment is not allowed when the object is empty. Use subscripted assignment to create an array element.
Afficher commentaires plus anciens
Hello!
I was developed a software with app designer and connect all values in a constructor class (this connection is running). But when I click in Run button, I need to access the function Positive_Time(load, tnt, analysis) in Class_Load and presents this error. Can you help me?
Property assignment is not allowed when the object is empty. Use subscripted
assignment to create an array element.
Error in Class_Load/Positive_Time (line 222)
load.tnt = tnt;
Here my Class_TNT
classdef Class_TNT
properties (SetAccess = public, GetAccess = public)
Z = 0;
W = 0;
type = 0;
negative = 0;
end
methods
function tnt = Class_TNT(W, Z, type, negative)
if (nargin > 0)
tnt.Z = Z;
tnt.W = W;
tnt.type = type;
tnt.negative = negative;
else
tnt.Z = 5;
tnt.W = 10;
tnt.type = 1;
tnt.negative = 1;
end
end
end
end
Here, my Class_Load
classdef Class_Load
properties (SetAccess = public, GetAccess = public)
tnt Class_TNT % TNT's properties
analysis Class_TypeAnalysis % Type Analysis propertie
td = 0; % Variable about the time that is during the
end
methods
function load = Class_Load(tnt, analysis)
if (nargin > 0)
load.Positive_Time(load, tnt, analysis);
else
load.tnt = Class_TNT(); % Empty constructor
end
end
end
methods
function load = Positive_Time(load, tnt, analysis)
load.tnt = tnt;
load.analysis = analysis;
type = load.tnt.type;
Z = load.tnt.Z;
W = load.tnt.W;
switch type
case 1
if (0.20993 < Z && Z <= 1.0355)
load.td = 0.001 * ( 2.2064 * Z^3 - 0.3363 * Z^2 - ...
0.5644 * Z + 0.3756 ) * ( W^(1/3) );
elseif (4.001 < Z)
load.td = 0.001 * ( 1.5602 * log(Z) +1.2416 ) * ...
( W^(1/3) );
end
case 2
if (0.2210 < Z && Z <= 0.7790)
load.td = 0.001 * ( 4.2668 * Z^3 - 1.9736 * Z^2 + ...
0.132 * Z + 0.2145 ) * ( W^(1/3) );
elseif (3.7612 < Z)
load.td = 0.001 * ( - 0.0029 * Z^2 + 0.2159 * Z + ...
2.1382 ) * ( W^(1/3) );
end
end
end
end
end
6 commentaires
per isakson
le 17 Juin 2020
load.Positive_Time(load, tnt, analysis);
should be
load.Positive_Time( tnt, analysis );
That's the only problem I found.
Ana Reis
le 18 Juin 2020
I gather from your post that you don't know what the load object contains at the moment that the error occurs? You should know - it's the kind of information that routine use of the debugger would give you:
Ana Reis
le 23 Juin 2020
Image Analyst
le 23 Juin 2020
Of course, everyone uses breakpoints.
load() is a built in function. It's a very, very bad idea to call your returned structure "load" or any other built-in function name. Pick another name than load.
Attach your class file, and your test file that calls it if you want more help.
Walter Roberson
le 23 Juin 2020
function load = Class_Load(tnt, analysis)
if (nargin > 0)
load.Positive_Time(load, tnt, analysis);
You have no class property named load so the load in the argument does not refer to any class property or any input variable. You have an output variable named load but you have not assigned to it, so it does not exist yet. Therefore the load refers to the load() function, which would default to loading matlab.mat if it can find it, returning the loaded variables in the form of a struct. But then load.Positive_Time does not exist to pass the result into.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Identification 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!