m file to instead save button in set path dialog

Go the Home tab and, in the Environment section, click Set Path. Then we will open the Set Path dialog box, there is a 'Save' button, now I want to use a M-file to achieve the 'save' button's function, how to do this? Use 'Savepath()'? I do not want to change any path, no add, no move, no remove, just save. Like I open this dialog, do nothing, just click 'save' button and close the dialog, now I want to use M-file to do this. just save. how? thanks~
set_path.png

 Accepted Answer

matlabpath( strjoin(Cell_Array_Of_Character_Vectors, pathsep) )

17 Comments

kei hin
kei hin on 17 Jan 2019
Edited: kei hin on 17 Jan 2019
thank you so much, but I don't understand, I use R2011b, I don't have 'strjoin'...
Your diagram claims you are using R2017a, not R2011b...
temp = repmat({pathsep}, 1, numel(Cell_Array_Of_Character_Vectors));
temp{end} = ''; %no separator on the last one
temp = reshape([reshape(Cell_Array_Of_Character_Vectors, 1, []); temp], 1, []);
temp = horzcat(temp{:});
matlabpath( temp );
Here Cell_Array_Of_Character_Vectors is a cell array of character vector of the path elements to be stored.
But perhaps I have misunderstood. My solution is for the situation that you somehow know the complete list of items to use for the path, but you do not want to store that list permanently. My solution is not for the case where you have called pathtool in your program to open up the GUI and you want the code to somehow click "Save" without the user having to click it.
The case where you have a complete list of items to use to replace the path is not common (except that the initial path is loaded at startup time.) Much more common is the situation where you want to add a few specific locations to the path and continue executing: that case is better handled a completely different way, by calling addpath()
sorry for my english, I don't understand... I just want to konw how to use a command to do the things which same as click the 'save' button.
Actually, I have a tool to change some setting to matlab environment, then I have to open the set path dialog and click 'save' button without any change then close the dialog, If I don't do this, I will got something wrong I don't konw, maybe lost path I guess. I hate this handwork(open-click save button-close), so I want a command...do we have~ thanks
For example, I want to creat a new *.m, I can use the menu bar(like click 'save' button), or I can use 'edit' command(I want this command).
"Actually, I have a tool to change some setting to matlab environment, then I have to open the set path dialog and click 'save' button without any change then close the dialog"
Ahhh, so that is the real problem that you are trying to solve: http://xyproblem.info/
It sounds like the tool might not be working properly. Can you give us a link or upload the tool?
kei hin
kei hin on 17 Jan 2019
Edited: kei hin on 17 Jan 2019
sorry, the tool is confidential, so I really don't know the detail of the tool... I really want to let that developer stand by to click save button when I need...
Java Robot Class can potentially click for you. It is a nuisance to get right through.
how about 'savepath'
No. savepath cannot click the save button for you, and so cannot close the pathtool you are opening. Furthermore savepath saves the path to disk, which you specifically do not want to do.
kei hin
kei hin on 18 Jan 2019
Edited: kei hin on 18 Jan 2019
I don't want let m-file to click the save button or close the pathtool in real(I don't want and will not open the pathtool), I just want a same result like the save button clicked without pathtool opened or closed. You mean that if I use savepath in D:\abc then the savepath function will add this path(D:\abc) into the path list? So can we use some parameter to avoid it? Like
savepath(pathlist_in_disk, 'null') %dummy
ah you have a problem . Clicking the Save button in pathtool does save to disk but you do not want the change saved to disk.
The code I already posted changes the execution MATLAB path without changing the path stored on disk.
kei hin
kei hin on 18 Jan 2019
Edited: kei hin on 23 Jan 2019
open path set dialog--click save button--close, there is no change from me, I didn't do the add or move or else. If just click the save button will save someting to disk, it doesn't matter, anything the save button did is allowed. So I want a command to do what the save button do, can I?
Click save button in pathtool dialog is same to 'savepath' in command window, isn't it?
I poked into the resources and can confirm that pathool save dialog invokes MATLAB's savepath()
where can I find the code of pathtool? I want to know the details.
And if I want add a path, I can click add in pathtool then click save and close, can I use 'addpath' in command window? Should I have to use 'savepath' after 'addpath' in command window?
To get the code for pathtool, you would need to either work for Mathworks or else buy enough of the company itself to be entitled to the source code.
addpath() changes MATLAB's in-memory idea of the path. savepath() writes path data to a file.
aha...OK...Let's back to the question, I can use 'savepath' to instead click save button in pathtool dialog right? So can you edit your first answer, and I will accept it.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2011b

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!