1 %USER_STRING Get/
set a user specific
string 4 %
string = user_string(string_name)
5 % saved = user_string(string_name, new_string)
7 % Function to
get and
set a
string in a system or user specific file. This
8 % enables,
for example, system specific paths to binaries to be saved.
11 % string_name - String containing the name of the
string required. The
12 %
string is extracted from a file called (string_name).txt,
13 % stored in the same directory as user_string.m.
14 % new_string - The
new string to be saved under the name given by
18 %
string - The currently saved
string. Default:
''.
19 % saved - Boolean indicating whether the save was succesful
21 % Copyright (C) Oliver Woodford 2011-2013
23 % This method of saving paths avoids changing .m files which might be in a
24 % version control system. Instead it saves the user dependent paths in
25 % separate files with a .txt extension, which need not be checked in to
26 % the version control system. Thank you to Jonas Dorn for suggesting this
29 % 10/01/2013 - Access files in text, not binary mode, as latter can cause
30 % errors. Thanks to Christian for pointing this out.
32 function
string = user_string(string_name,
string)
33 if ~ischar(string_name)
34 error('string_name must be a
string.');
36 % Create the full filename
37 string_name = fullfile(fileparts(mfilename('fullpath')), '.ignore', [string_name '.txt']);
41 error('new_string must be a
string.');
43 % Make sure the save directory exists
44 dname = fileparts(string_name);
45 if ~exist(dname, 'dir')
46 % Create the directory
58 fileattrib(dname, '+h');
63 fid = fopen(string_name, 'wt');
69 fprintf(fid, '%s',
string);
79 fid = fopen(string_name, 'rt');