matlab-class

Weird error while using constant properties in class

大兔子大兔子 提交于 2021-01-29 06:46:59
问题 I am trying to save functions as variables inside a class so I can reach them in an ordered manner. However, whenever I try to pull any constant from the following class, I get the following error. %FORMULAS Summary of this class goes here % Detailed explanation goes here properties (Constant) %F.heatCapacityOfLiquid t = @(z) z *2 end properties (Constant) enthalpyChange = @(constants, temperatureIn, temperatureOut)integral(@(temperature)(@(constants, temperature)... constants(1)... +

indexed object dot notation method gives scalar property

孤者浪人 提交于 2020-01-11 18:51:58
问题 I'm seeing an issue when I try and reference an object property after having used a dot notation to apply a method. it only occurs when I try to index the initial object classdef myclassexample properties data end methods function obj = procData(obj) if numel(obj)>1 for i = 1:numel(obj) obj(i) = obj(i).procData; end return end %do some processing obj.data = abs(obj.data); end end end then assigning the following A = myclassexample; A(1).data= - -1; A(2).data = -2; when calling the whole array

indexed object dot notation method gives scalar property

偶尔善良 提交于 2020-01-11 18:50:48
问题 I'm seeing an issue when I try and reference an object property after having used a dot notation to apply a method. it only occurs when I try to index the initial object classdef myclassexample properties data end methods function obj = procData(obj) if numel(obj)>1 for i = 1:numel(obj) obj(i) = obj(i).procData; end return end %do some processing obj.data = abs(obj.data); end end end then assigning the following A = myclassexample; A(1).data= - -1; A(2).data = -2; when calling the whole array

How do I create an array of abstract class objects in MATLAB?

强颜欢笑 提交于 2019-12-30 00:59:09
问题 As an example, suppose I have created an abstract class called Shape and two subclasses called Circle and Rectangle that both implement an (abstract) method called Draw . I would like to be able to create a number of Circle and Rectangle objects, store them in an array and call Draw on each array object by iterating through the array. I have tried something like the following: Shape.m: classdef (Abstract) Shape < handle methods (Abstract) Draw(obj); end end Circle.m: classdef Circle < Shape

How can I tell how much memory a handle object uses in matlab

孤街浪徒 提交于 2019-12-21 07:07:15
问题 If I declare an object to be a subclass of handle classdef obj < handle my object is now essentially a "pointer" to some memory somewhere. How do I find out how much memory my object is using up? For example, say I have a class foo with a field bar classdef foo < handle properties bar = randn(1000); end bar takes up 8 megabytes (8 bytes * 1 million numbers) but if I type obj = foo(); whos('obj'); I get Name Size Bytes Class Attributes obj 1x1 60 foo How do I find out how much total memory obj

Why do I get a “Too many input arguments” error when passing in proper parameters?

一世执手 提交于 2019-12-19 10:16:29
问题 Why am I getting an error: ??? Error using ==> ensureCellType Too many input arguments. Error in ==> usage_dynamicVariableNaming at 11 result = dataHolder.ensureCellType(str); when I am passing in right number of parameters? % USAGE: clear all; clc; elementNames = {'area_12345[<>]6789', 'apollo123', 'guruX', 'ok'}; elementTypes = {'string', 'specialChar', 'int', 'float'}; elementValues = {'charlie', 'vvv', '09', '123.321'}; dataHolder = dynamicVariableNaming; str = 'test'; result = dataHolder

Defining enumerations and constants locally in MATLAB

心已入冬 提交于 2019-12-11 11:57:45
问题 I would like to define enumerations and constants locally within the scope of a function. I saw that MATLAB provides enumerations and constants as part of its object-oriented programming framework. However, if you try to define them within the scope of a function, they don't work. E.g. MATLAB complains with "Parse error: invalid syntax" if you try the following: function output = my_function(input) classdef my_constants properties (Constant) x = 0.2; y = 0.4; z = 0.5; end end classdef colors

Global variables for class library in matlab

断了今生、忘了曾经 提交于 2019-12-07 10:04:11
问题 I have several matlab classes declared. How could I declare constants which are seen in all classes? For instance : these constants can be physical constants which are used in methods of all classes. The first thing coming to mind is using global variables. Is there any better way? It will be nice to declare these constants in a separate file. 回答1: A class containing the constants is a nice clean way to do this. See the article in Matlab documentation: http://www.mathworks.com/help/matlab

How can I validate a function handle as an input argument?

[亡魂溺海] 提交于 2019-12-06 06:33:52
问题 I have a class that has a function handle as one of its properties . classdef MyClass properties hfun %function handle end methods function obj = Myclass(hfun,...) %PROBLEM: validate that the input argument hfun is the right kind of function if ~isa(hfun,'function_handle') || nargin(hfun)~=1 || nargout(hfun)~=1 error('hfun must be a function handle with 1 input and 1 output'); end obj.hfun = hfun; end end end I'd like to make sure that the input argument hfun is a function handle with 1 input

Global variables for class library in matlab

有些话、适合烂在心里 提交于 2019-12-05 18:13:38
I have several matlab classes declared. How could I declare constants which are seen in all classes? For instance : these constants can be physical constants which are used in methods of all classes. The first thing coming to mind is using global variables. Is there any better way? It will be nice to declare these constants in a separate file. A class containing the constants is a nice clean way to do this. See the article in Matlab documentation: http://www.mathworks.com/help/matlab/matlab_oop/properties-with-constant-values.html For example, if you create a class called NamedConst as follows