Data.m 2.12 KB
Newer Older
1
2
3
4
5
classdef (Abstract) Data < handle & matlab.mixin.Heterogeneous
    %EXPORTDATA Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
6
7
8
        basepath char = '.';
        foldername char = '.';
        filename char = 'data';
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        N = 201;        
    end
        
    methods
        
        function obj = Data(varargin)
           for arg=1:2:length(varargin)
               obj.(varargin{arg}) = varargin{arg + 1}; 
           end
        end
        
        function p = path(obj, k)
            if ~exist('k', 'var')
                k = '';
            end
            
           p = [obj.absolutepath filesep obj.addExtension(k)]; 
        end
                
        function p = absolutepath(obj)
            p = [obj.basepath filesep obj.foldername];
        end
        
        function f = addExtension(obj, k)
            
            if ~exist('k', 'var')
                name = obj.filename;
            elseif ischar(k)
                name = [obj.filename k];
            elseif isnumeric(k)
                name = [obj.filename num2str(k)];
            end
            
            if isempty(regexpi(obj.filename, '\w*\.(dat)$'))
                f = [name '.dat'];
            else
                error('Dateiname muss ohne Endung übergebenw erden!');
            end                        
        end
        
    end
    
    methods(Sealed)
        function export(obj)
            for k = 1:length(obj)
               if ~obj(k).isempty
                   
56
                  if ~isfolder(obj(k).absolutepath)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
                     mkdir(obj(k).absolutepath); 
                  end
                   
                  obj(k).innerexport();
                  
                  fprintf(['export: %s \n'], obj(k).path);
                  
               else
                  warning(['Object ' num2str(k) ' is empty']);
               end
            end
        end   
    end 
   
    methods (Abstract, Access = protected)
       innerexport(obj); 
    end
    
    methods (Static)
        function exportAll( exp_struct)
           structfun(@(x)export(x), exp_struct); 
        end
    end
end