set method for class

조회 수: 2 (최근 30일)
jeff wu
jeff wu 2012년 4월 21일
Hy I got this class, that i use to store some data. i made the festi property dependant but now i realize that i have to call this function really often ( 100 000) during the program and since there are several awitches and severeal other defenitions within it ( i didt copy the hole code) it makes it to slow. actually i use the values a lot but i dont often change the values.
so it would be nice to save the container that would make it fatser because then i could reach the values throught the container without going throught all the swiches and ifs.
i copied my new solution unter the first try.
i would be thankfull for any help thanx
classdef material
properties
name %string
strengthClass %string
end%properties
properties (Dependent)
festi % dictionary or containers.Map
end%properties
methods
function m = material(name,strengthClass)
m.name=name;
m.strengthClass = strengthClass;
end
function obj = get.festi(obj)
F_NadelundLaub=[14,16... % some matriy with date
keys_NHuLH={'fmk','ft0k','ft90k','fc0k'};
F_BSH=[24,.... other matrix with data
...
if strcmp(obj.name,'Nadelholz')
switch obj.strengthClass
case 'C14'
values =F_NadelundLaub(:,1);
case 'C16'...
end
end
end %eleseif
val = containers.Map(keys,values);
end
end %methods
end %CLASS
% the other way
classdef material
properties
name %string
strengthClass %string
festi % dictionary
end%properties
methods
function m = material(name,strengthClass)
m.name=name;
m.strengthClass = strengthClass;
m.festi = Festigkeitswerte2(m.name,m.strengthClass); % this one works
end
end %methods
end %CLASS
% to change it outside the class i could use:
instanceofMaterial.festi = Festigkeitswerte2('Nadelholz','C14')
% this one works too but im looking for a mor eleagant way

답변 (1개)

Daniel Shub
Daniel Shub 2012년 4월 22일
It looks like the festi property only depends on the strengthClass property. You could create a set method for strengthClass which updates festi.

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by