Reputation: 1079
I want to create a function that finds a specific path in Matlab.
The issue is that the path is variable depending on the versions of my program I am working, so
..../...../v1.1/file.m
or
.../...../v1.2/file.m
I would like to know if there is a function to use for hte variable name. Also if the path is too long and I do not want to write it all, is there a symbol that replaces all the previos part. I mean:
strfind(path,$/v1.1/file.m);
But I am not sure of it.
I would appreciate some help!
Upvotes: 0
Views: 70
Reputation: 526
If you are looking in the path for an instance of the version number, v1.X, then you should just feed it too regexp.
With regard to storing the root of the path and combining it with the version specific portion, I usually use fullfile which handles the path separator for you and makes your code system independent. Finally, in order to handle the version numbering I use sprintf. A lot of people in my lab prefer to use array concatenation, but I find code like that harder to read.
root = matlabroot; % Just an example of a root
version = 1; % Make this a variable in case of future upgrades
subversion = 1; % The actual part from the question
fullPth = fullfile( root, sprintf('v%i.%i', version, subversion), 'file1' );
Upvotes: 1
Reputation: 3204
Do you want to do something similar to this?
versionOfProgram = 'v1.2';
f = fullfile('C:', 'Applications', 'matlab', versionOfProgram, 'file.m');
Upvotes: 0