set method for class
    5 views (last 30 days)
  
       Show older comments
    
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
0 Comments
Answers (1)
  Daniel Shub
      
      
 on 22 Apr 2012
        It looks like the festi property only depends on the strengthClass property. You could create a set method for strengthClass which updates festi.
0 Comments
See Also
Categories
				Find more on Data Type Conversion 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!
