You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
m file to instead save button in set path dialog
3 views (last 30 days)
Show older comments
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~
Accepted Answer
Walter Roberson
on 17 Jan 2019
matlabpath( strjoin(Cell_Array_Of_Character_Vectors, pathsep) )
17 Comments
Walter Roberson
on 17 Jan 2019
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()
kei hin
on 17 Jan 2019
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).
Stephen23
on 17 Jan 2019
"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?
Walter Roberson
on 17 Jan 2019
Java Robot Class can potentially click for you. It is a nuisance to get right through.
Walter Roberson
on 18 Jan 2019
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
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
Walter Roberson
on 18 Jan 2019
Edited: Walter Roberson
on 21 Jan 2019
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
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?
kei hin
on 23 Jan 2019
Click save button in pathtool dialog is same to 'savepath' in command window, isn't it?
Walter Roberson
on 23 Jan 2019
I poked into the resources and can confirm that pathool save dialog invokes MATLAB's savepath()
kei hin
on 23 Jan 2019
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?
Walter Roberson
on 23 Jan 2019
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.
kei hin
on 23 Jan 2019
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.
Walter Roberson
on 23 Jan 2019
If you just want to put a path into effect then the code from https://www.mathworks.com/matlabcentral/answers/440143-m-file-to-instead-save-button-in-set-path-dialog#comment_661311 does that without using savepath() .
More Answers (0)
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)