Add folder path based on run script matlab










0















Don't know why this isn't working anymore. Very simple. I have a script with a folder in the same path. The folder contains a series of m files for the script to work.



Originally I simply would use



addpath('.../utilities/);


when the script was first run. but recently I started receiving this error




Warning: Name is nonexistent or not a directory: ...utilities



In path (line 109)



In addpath (line 88)



In Myrunningcode (line 101)




and I don't know why.



I fixed the problem by running the following code



p = mfilename('fullpath');
[filepath,~,~] = fileparts(p);
addpath([filepath,'/utilities/']);


At least I would like to know why this error occurred.



Here is my directory setup. I use windows 10 and matlab 2016a.
enter image description here










share|improve this question
























  • What changed? OS? MATLAB version?

    – Ander Biguri
    Nov 14 '18 at 9:59











  • nothing changed from what I can tell. I'm using matlab 2016a on windows 10.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:02






  • 1





    Use fullfile instead of manually concatenating with (OS dependent) file separators. If your error is a direct copy of the actual error, it would appear you've used a backslash where your example cites a forward slash, this inconsistency is a red flag. The issue is likely that your current directory (pwd) is not the same as the file location (perhaps it was when your code worked) - the relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.

    – Wolfie
    Nov 14 '18 at 10:07












  • Is there a simpler method to adding a folder based on script location or is my workaround good enough for what I am doing? As a side question, Is it possible to know if a folder path was added to the list? I don't think it is wise to call addpath every time I run the script.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:13











  • @Wolfie no, I use this in both linux and windows. in Windows, if you do addpath('.../utilities/); you will get a warning using ...utilities, as it knows you mean that. Using / will make the code OS-independent.

    – Ander Biguri
    Nov 14 '18 at 10:16
















0















Don't know why this isn't working anymore. Very simple. I have a script with a folder in the same path. The folder contains a series of m files for the script to work.



Originally I simply would use



addpath('.../utilities/);


when the script was first run. but recently I started receiving this error




Warning: Name is nonexistent or not a directory: ...utilities



In path (line 109)



In addpath (line 88)



In Myrunningcode (line 101)




and I don't know why.



I fixed the problem by running the following code



p = mfilename('fullpath');
[filepath,~,~] = fileparts(p);
addpath([filepath,'/utilities/']);


At least I would like to know why this error occurred.



Here is my directory setup. I use windows 10 and matlab 2016a.
enter image description here










share|improve this question
























  • What changed? OS? MATLAB version?

    – Ander Biguri
    Nov 14 '18 at 9:59











  • nothing changed from what I can tell. I'm using matlab 2016a on windows 10.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:02






  • 1





    Use fullfile instead of manually concatenating with (OS dependent) file separators. If your error is a direct copy of the actual error, it would appear you've used a backslash where your example cites a forward slash, this inconsistency is a red flag. The issue is likely that your current directory (pwd) is not the same as the file location (perhaps it was when your code worked) - the relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.

    – Wolfie
    Nov 14 '18 at 10:07












  • Is there a simpler method to adding a folder based on script location or is my workaround good enough for what I am doing? As a side question, Is it possible to know if a folder path was added to the list? I don't think it is wise to call addpath every time I run the script.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:13











  • @Wolfie no, I use this in both linux and windows. in Windows, if you do addpath('.../utilities/); you will get a warning using ...utilities, as it knows you mean that. Using / will make the code OS-independent.

    – Ander Biguri
    Nov 14 '18 at 10:16














0












0








0








Don't know why this isn't working anymore. Very simple. I have a script with a folder in the same path. The folder contains a series of m files for the script to work.



Originally I simply would use



addpath('.../utilities/);


when the script was first run. but recently I started receiving this error




Warning: Name is nonexistent or not a directory: ...utilities



In path (line 109)



In addpath (line 88)



In Myrunningcode (line 101)




and I don't know why.



I fixed the problem by running the following code



p = mfilename('fullpath');
[filepath,~,~] = fileparts(p);
addpath([filepath,'/utilities/']);


At least I would like to know why this error occurred.



Here is my directory setup. I use windows 10 and matlab 2016a.
enter image description here










share|improve this question
















Don't know why this isn't working anymore. Very simple. I have a script with a folder in the same path. The folder contains a series of m files for the script to work.



Originally I simply would use



addpath('.../utilities/);


when the script was first run. but recently I started receiving this error




Warning: Name is nonexistent or not a directory: ...utilities



In path (line 109)



In addpath (line 88)



In Myrunningcode (line 101)




and I don't know why.



I fixed the problem by running the following code



p = mfilename('fullpath');
[filepath,~,~] = fileparts(p);
addpath([filepath,'/utilities/']);


At least I would like to know why this error occurred.



Here is my directory setup. I use windows 10 and matlab 2016a.
enter image description here







matlab path relative-path






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 12:35









Wolfie

16.5k51745




16.5k51745










asked Nov 14 '18 at 9:49









Hojo.TimberwolfHojo.Timberwolf

398214




398214












  • What changed? OS? MATLAB version?

    – Ander Biguri
    Nov 14 '18 at 9:59











  • nothing changed from what I can tell. I'm using matlab 2016a on windows 10.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:02






  • 1





    Use fullfile instead of manually concatenating with (OS dependent) file separators. If your error is a direct copy of the actual error, it would appear you've used a backslash where your example cites a forward slash, this inconsistency is a red flag. The issue is likely that your current directory (pwd) is not the same as the file location (perhaps it was when your code worked) - the relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.

    – Wolfie
    Nov 14 '18 at 10:07












  • Is there a simpler method to adding a folder based on script location or is my workaround good enough for what I am doing? As a side question, Is it possible to know if a folder path was added to the list? I don't think it is wise to call addpath every time I run the script.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:13











  • @Wolfie no, I use this in both linux and windows. in Windows, if you do addpath('.../utilities/); you will get a warning using ...utilities, as it knows you mean that. Using / will make the code OS-independent.

    – Ander Biguri
    Nov 14 '18 at 10:16


















  • What changed? OS? MATLAB version?

    – Ander Biguri
    Nov 14 '18 at 9:59











  • nothing changed from what I can tell. I'm using matlab 2016a on windows 10.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:02






  • 1





    Use fullfile instead of manually concatenating with (OS dependent) file separators. If your error is a direct copy of the actual error, it would appear you've used a backslash where your example cites a forward slash, this inconsistency is a red flag. The issue is likely that your current directory (pwd) is not the same as the file location (perhaps it was when your code worked) - the relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.

    – Wolfie
    Nov 14 '18 at 10:07












  • Is there a simpler method to adding a folder based on script location or is my workaround good enough for what I am doing? As a side question, Is it possible to know if a folder path was added to the list? I don't think it is wise to call addpath every time I run the script.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:13











  • @Wolfie no, I use this in both linux and windows. in Windows, if you do addpath('.../utilities/); you will get a warning using ...utilities, as it knows you mean that. Using / will make the code OS-independent.

    – Ander Biguri
    Nov 14 '18 at 10:16

















What changed? OS? MATLAB version?

– Ander Biguri
Nov 14 '18 at 9:59





What changed? OS? MATLAB version?

– Ander Biguri
Nov 14 '18 at 9:59













nothing changed from what I can tell. I'm using matlab 2016a on windows 10.

– Hojo.Timberwolf
Nov 14 '18 at 10:02





nothing changed from what I can tell. I'm using matlab 2016a on windows 10.

– Hojo.Timberwolf
Nov 14 '18 at 10:02




1




1





Use fullfile instead of manually concatenating with (OS dependent) file separators. If your error is a direct copy of the actual error, it would appear you've used a backslash where your example cites a forward slash, this inconsistency is a red flag. The issue is likely that your current directory (pwd) is not the same as the file location (perhaps it was when your code worked) - the relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.

– Wolfie
Nov 14 '18 at 10:07






Use fullfile instead of manually concatenating with (OS dependent) file separators. If your error is a direct copy of the actual error, it would appear you've used a backslash where your example cites a forward slash, this inconsistency is a red flag. The issue is likely that your current directory (pwd) is not the same as the file location (perhaps it was when your code worked) - the relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.

– Wolfie
Nov 14 '18 at 10:07














Is there a simpler method to adding a folder based on script location or is my workaround good enough for what I am doing? As a side question, Is it possible to know if a folder path was added to the list? I don't think it is wise to call addpath every time I run the script.

– Hojo.Timberwolf
Nov 14 '18 at 10:13





Is there a simpler method to adding a folder based on script location or is my workaround good enough for what I am doing? As a side question, Is it possible to know if a folder path was added to the list? I don't think it is wise to call addpath every time I run the script.

– Hojo.Timberwolf
Nov 14 '18 at 10:13













@Wolfie no, I use this in both linux and windows. in Windows, if you do addpath('.../utilities/); you will get a warning using ...utilities, as it knows you mean that. Using / will make the code OS-independent.

– Ander Biguri
Nov 14 '18 at 10:16






@Wolfie no, I use this in both linux and windows. in Windows, if you do addpath('.../utilities/); you will get a warning using ...utilities, as it knows you mean that. Using / will make the code OS-independent.

– Ander Biguri
Nov 14 '18 at 10:16













2 Answers
2






active

oldest

votes


















3














The issue is likely that your current directory (pwd) is not the same as the file location. The relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.



The first solution is your own, but you can do it in one line:



addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );


Then the quickest way to check if your files are already on the path is using which:



% Assuming that myFile.m is within the utilities folder, and not shadowed elsewhere.
% If utilities is on the path, which('myFile') will not be empty.
if isempty( which( 'myFile' ) )
addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );
end


Alternatively, you could pair the above check with a persistent flag variable, so you don't have to repeat the check if you re-enter the function.



Note that addpath isn't particularly slow, it's genpath you want to avoid if you were to add a load of subdirectories too.



Aside: It's good to use fullfile instead of manually concatenating with (OS dependent) file separators. Less room for error (e.g. double slashes) even if you're always using the same OS.






share|improve this answer




















  • 1





    But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

    – Ander Biguri
    Nov 14 '18 at 10:24







  • 1





    @AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

    – Wolfie
    Nov 14 '18 at 10:27







  • 1





    Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

    – Ander Biguri
    Nov 14 '18 at 10:29


















2














The correct way to include a relative folder is:



addpath('./utilities/');


with a single dot.



This has worked (and works) since the existence of relative folders, AFAIK, so you should be able to use it without fear of deprecation






share|improve this answer























  • I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:05







  • 1





    @Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

    – Ander Biguri
    Nov 14 '18 at 10:18











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297233%2fadd-folder-path-based-on-run-script-matlab%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














The issue is likely that your current directory (pwd) is not the same as the file location. The relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.



The first solution is your own, but you can do it in one line:



addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );


Then the quickest way to check if your files are already on the path is using which:



% Assuming that myFile.m is within the utilities folder, and not shadowed elsewhere.
% If utilities is on the path, which('myFile') will not be empty.
if isempty( which( 'myFile' ) )
addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );
end


Alternatively, you could pair the above check with a persistent flag variable, so you don't have to repeat the check if you re-enter the function.



Note that addpath isn't particularly slow, it's genpath you want to avoid if you were to add a load of subdirectories too.



Aside: It's good to use fullfile instead of manually concatenating with (OS dependent) file separators. Less room for error (e.g. double slashes) even if you're always using the same OS.






share|improve this answer




















  • 1





    But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

    – Ander Biguri
    Nov 14 '18 at 10:24







  • 1





    @AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

    – Wolfie
    Nov 14 '18 at 10:27







  • 1





    Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

    – Ander Biguri
    Nov 14 '18 at 10:29















3














The issue is likely that your current directory (pwd) is not the same as the file location. The relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.



The first solution is your own, but you can do it in one line:



addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );


Then the quickest way to check if your files are already on the path is using which:



% Assuming that myFile.m is within the utilities folder, and not shadowed elsewhere.
% If utilities is on the path, which('myFile') will not be empty.
if isempty( which( 'myFile' ) )
addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );
end


Alternatively, you could pair the above check with a persistent flag variable, so you don't have to repeat the check if you re-enter the function.



Note that addpath isn't particularly slow, it's genpath you want to avoid if you were to add a load of subdirectories too.



Aside: It's good to use fullfile instead of manually concatenating with (OS dependent) file separators. Less room for error (e.g. double slashes) even if you're always using the same OS.






share|improve this answer




















  • 1





    But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

    – Ander Biguri
    Nov 14 '18 at 10:24







  • 1





    @AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

    – Wolfie
    Nov 14 '18 at 10:27







  • 1





    Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

    – Ander Biguri
    Nov 14 '18 at 10:29













3












3








3







The issue is likely that your current directory (pwd) is not the same as the file location. The relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.



The first solution is your own, but you can do it in one line:



addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );


Then the quickest way to check if your files are already on the path is using which:



% Assuming that myFile.m is within the utilities folder, and not shadowed elsewhere.
% If utilities is on the path, which('myFile') will not be empty.
if isempty( which( 'myFile' ) )
addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );
end


Alternatively, you could pair the above check with a persistent flag variable, so you don't have to repeat the check if you re-enter the function.



Note that addpath isn't particularly slow, it's genpath you want to avoid if you were to add a load of subdirectories too.



Aside: It's good to use fullfile instead of manually concatenating with (OS dependent) file separators. Less room for error (e.g. double slashes) even if you're always using the same OS.






share|improve this answer















The issue is likely that your current directory (pwd) is not the same as the file location. The relative directory isn't relative to the current script, it's relative to pwd, hence why the mfilename workaround fixes your issue.



The first solution is your own, but you can do it in one line:



addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );


Then the quickest way to check if your files are already on the path is using which:



% Assuming that myFile.m is within the utilities folder, and not shadowed elsewhere.
% If utilities is on the path, which('myFile') will not be empty.
if isempty( which( 'myFile' ) )
addpath( fullfile( fileparts( mfilename('fullpath') ), 'utilities' ) );
end


Alternatively, you could pair the above check with a persistent flag variable, so you don't have to repeat the check if you re-enter the function.



Note that addpath isn't particularly slow, it's genpath you want to avoid if you were to add a load of subdirectories too.



Aside: It's good to use fullfile instead of manually concatenating with (OS dependent) file separators. Less room for error (e.g. double slashes) even if you're always using the same OS.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 10:25

























answered Nov 14 '18 at 10:23









WolfieWolfie

16.5k51745




16.5k51745







  • 1





    But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

    – Ander Biguri
    Nov 14 '18 at 10:24







  • 1





    @AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

    – Wolfie
    Nov 14 '18 at 10:27







  • 1





    Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

    – Ander Biguri
    Nov 14 '18 at 10:29












  • 1





    But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

    – Ander Biguri
    Nov 14 '18 at 10:24







  • 1





    @AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

    – Wolfie
    Nov 14 '18 at 10:27







  • 1





    Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

    – Ander Biguri
    Nov 14 '18 at 10:29







1




1





But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

– Ander Biguri
Nov 14 '18 at 10:24






But as a note: addpath('./utilities/'); is OS independent. I agree with you with the timing of addpath. Its probably better to just add it to path multiple times than to check which.

– Ander Biguri
Nov 14 '18 at 10:24





1




1





@AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

– Wolfie
Nov 14 '18 at 10:27






@AnderBiguri Not disputing that, I'm suggesting the use of fullfile to avoid the [filepath,'/utilities/'] which the OP used, assuming relative paths won't work because the user in the wrong location anyway.

– Wolfie
Nov 14 '18 at 10:27





1




1





Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

– Ander Biguri
Nov 14 '18 at 10:29





Certainly this is a good answer for what OP needs ;). One could argue that you may want to do a different thing by design, i.e. you may want to force the user of the script to be in the path above the folders, but its unrelated to the question and its case-specific. This answer is better than mine because it solves the problem that OP has I think ;)

– Ander Biguri
Nov 14 '18 at 10:29













2














The correct way to include a relative folder is:



addpath('./utilities/');


with a single dot.



This has worked (and works) since the existence of relative folders, AFAIK, so you should be able to use it without fear of deprecation






share|improve this answer























  • I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:05







  • 1





    @Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

    – Ander Biguri
    Nov 14 '18 at 10:18
















2














The correct way to include a relative folder is:



addpath('./utilities/');


with a single dot.



This has worked (and works) since the existence of relative folders, AFAIK, so you should be able to use it without fear of deprecation






share|improve this answer























  • I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:05







  • 1





    @Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

    – Ander Biguri
    Nov 14 '18 at 10:18














2












2








2







The correct way to include a relative folder is:



addpath('./utilities/');


with a single dot.



This has worked (and works) since the existence of relative folders, AFAIK, so you should be able to use it without fear of deprecation






share|improve this answer













The correct way to include a relative folder is:



addpath('./utilities/');


with a single dot.



This has worked (and works) since the existence of relative folders, AFAIK, so you should be able to use it without fear of deprecation







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 10:00









Ander BiguriAnder Biguri

26.5k105492




26.5k105492












  • I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:05







  • 1





    @Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

    – Ander Biguri
    Nov 14 '18 at 10:18


















  • I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

    – Hojo.Timberwolf
    Nov 14 '18 at 10:05







  • 1





    @Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

    – Ander Biguri
    Nov 14 '18 at 10:18

















I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

– Hojo.Timberwolf
Nov 14 '18 at 10:05






I tried this but the error still persists. matlab claims the folder doesn't exist even though I can see it in the directory next to the m-file. If I give a full path than the path is added with no problems.

– Hojo.Timberwolf
Nov 14 '18 at 10:05





1




1





@Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

– Ander Biguri
Nov 14 '18 at 10:18






@Hojo.Timberwolf Is your code running in the upper folder to that one? I mean, I have used this in MATLAB 2014,2016,2017,2018, Windows 7,8,8.1,10, Ubuntu 16,17,18. It works. You need to be running the code in the folder that is directly above ./utilities though, as that is how a relative path is defined.

– Ander Biguri
Nov 14 '18 at 10:18


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297233%2fadd-folder-path-based-on-run-script-matlab%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20