Is it possible to update the text inside other scripts/functions using a separate script?
2 次查看(过去 30 天)
显示 更早的评论
In development of a new tool, I will want to update the version and date in each script when a new version is ready to be used. Right now there are multiple scripts that will need the update, and to save time, I would like to create a script that calls to each individual function to change the date and version.
Let's say I have a function with a header:
function test = dummy()
%% Header
% Name : dummy
% Rev : 3.0.0
% Date : 2022/03/28
% Author : Steven Manz
% Desc :
%
% REVISION HISTORY
% 1.0.0 : Initial release
% 3.0.0 : Reformatted entire tool for production use
%
% INPUTS
% -------------------------------------------------------------------------
end
...
Is it possible to write a script that will search for Rev and change the revision as well as the history, then change the date to the current date?
Using another function to change the text inside a separate function is something I have never tried before and cannot seem to find any information for anywhere else. Is this possible in MATLAB?
4 个评论
Rik
2022-3-28
.m files are stored as plain text. Since a few releases they are UTF-8 encoded by default, but if you don't use special characters in your char arrays/strings that doesn't matter. So all tools that work on txt files will work on m files.
采纳的回答
更多回答(1 个)
Steven Lord
2022-3-28
While you can store the revision history for a file in the file itself, if you're going to build a lot of tools for others to use I strongly recommend using a source control system or SCM. You can control certain types of SCMs from within MATLAB; the documentation section to which I linked discusses Git and SVN. One benefit an SCM gives you is that if you make a change and then need to undo that change, reverting it is usually pretty easy. If you've modified the main or sole copy of the file you need to try to remember what modifications you made to implement that change and that can be difficult especially if that change was large, was complicated, or it's been a while since you made it.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!