"Unable to Resolve Name set.Y_i" | Error with using object setter functions
Show older comments
I'm using a setter function for an object in a test program, but each time I try to use it, I get an error "Unable to resolve the name set.Y_i". I believe this is an issue with file locations, based on a few Google searches I've made on the issue, but I've found nothing helpful.
Here's the relavant code from the test file (test input is "5", or some other small number):
myLauncher = launcher(ini_height_launcher,ini_height_target,ini_velocity,distance_to_target,angle_of_lancher,bool_isCocked,rotatingBase_angle);
input2 = input('Change launcher''s height (meters): ');
myLauncher = set.Y_i(myLauncher,input2);
Here's the set function (I've tested it without the NAN check, same error):
function obj = set.Y_i(obj, A)
if(~isnan(A))
obj.Y_i = A;
else
fprintf("Function: set.Y_i\nInput is not a number!\n");
end
end
Answers (1)
Steven Lord
on 4 Mar 2020
Edited: Steven Lord
on 4 Mar 2020
As per the first Note on this documentation page "You cannot call property access methods directly. MATLAB calls these methods when you access property values."
If Y_i is a property of the launcher class (of which myLauncher is an instance) then your third line should be:
myLauncher.Y_i = input2;
You may want your property set method to throw an error instead of simply displaying a message. Users can (and often do) ignore status messages displayed by functions. It is possible to ignore an error (usually using a try / catch block) but you have to work a little more to ignore it.
Categories
Find more on Software Development in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!