m file to instead save button in set path dialog
3 次查看(过去 30 天)
显示 更早的评论
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~
采纳的回答
Walter Roberson
2019-1-17
matlabpath( strjoin(Cell_Array_Of_Character_Vectors, pathsep) )
17 个评论
Walter Roberson
2019-1-17
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
2019-1-17
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
2019-1-17
"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
2019-1-17
Java Robot Class can potentially click for you. It is a nuisance to get right through.
Walter Roberson
2019-1-18
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
2019-1-18
编辑:kei hin
2019-1-18
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
2019-1-18
编辑:Walter Roberson
2019-1-21
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
2019-1-18
编辑:kei hin
2019-1-23
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
2019-1-23
Click save button in pathtool dialog is same to 'savepath' in command window, isn't it?
Walter Roberson
2019-1-23
I poked into the resources and can confirm that pathool save dialog invokes MATLAB's savepath()
kei hin
2019-1-23
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
2019-1-23
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
2019-1-23
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
2019-1-23
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() .
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)