-
Notifications
You must be signed in to change notification settings - Fork 3
/
anatomy.m
48 lines (46 loc) · 1.28 KB
/
anatomy.m
1
2
3
4
5
6
7
8
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
function varargout=anatomy(fname,snumber)
% [t,d]=ANATOMY(fname,snumber)
%
% Anatomy of a proper and flexible function
%
% INPUT:
%
% fname A MATLAB m-file name string
% snumber Some number, e.g. pi
%
% OUTPUT:
%
% t A timestamp as a DATETIME array
% d A measure of file size
%
% SEE ALSO: MARK2MAT, DROP2MAT, BRINNO2MAT
%
% EXAMPLE:
%
% [a,b]=anatomy('demo1');
% [c,d]=anatomy(which('anatomy'),2)
%
% TESTED ON: MATLAB Version: 9.8.0.1451342 (R2020a) Update 5
%
% Last modified by fjsimons-at-alum.mit.edu, 01/11/2022
% Do something interesting with the input
if isempty(strfind(fname,'demo'))
% Like, find the creation time stamp of the first input
[~,b]=system(sprintf('GetFileInfo %s',which(fname)));
s=strfind(b,'created: ')+9;
t=datetime(b(s:s+18),'InputFormat','MM/dd/uuuu HH:mm:ss');
% And, find the file size, multiplied by the second input
[~,b]=system(sprintf('ls -l %s | awk ''{print $5}''',which(fname)));
d=str2num(b(1:length(b)-1))*snumber;
if isnat(t)
% This would be the Windows version
[~,b]=system('dir');
% ...
end
elseif strcmp(fname,'demo1')
% Call your own example... do check out DEFVAL, RAND, etc
[t,d]=anatomy(mfilename,1);
end
% Optional output
varns={t,d};
varargout=varns(1:nargout);