Making a *.m file "read only."
조회 수: 21 (최근 30일)
이전 댓글 표시
I have several *.m files that are finished. However, I would like to set breakpoints in the debugger and watch the flow of data through them. However, I do not want to accidentally modify any of this code. Is there some way to make these routines "read only" so I can't accidentally modify them? I know I can do it at the OS level but does Matlab have the functional ability to accomplish this.
댓글 수: 0
채택된 답변
Sean de Wolski
2015년 2월 17일
편집: Sean de Wolski
2015년 2월 17일
MATLAB doesn't have the ability to do this. However, you could use a source control system like SVN or GIT to monitor them. Then you'd be able to see if any changes had been made since the last commit and what those changes are (in case you do decide to add a comment or something!). In R2014b, you can do this from the current folder browser.
댓글 수: 0
추가 답변 (1개)
per isakson
2015년 2월 17일
편집: per isakson
2015년 2월 17일
I didn't read your question to the last sentence, but don't delete my answer.
I use this function, cmd_read_only to avoid editing files, which I open in the editor just to refresh my memory. Together with this file I have (on another computer) a shortcut that runs the file on the current file. Windows only!
function varargout = cmd_read_only( filespec, action )
% cmd_read_only sets or clears the attribute, read-only, of file
%
% Example:
% sts = cmd_read_only( 'c:\m\my_file.txt', 'on' )
% sts = cmd_read_only( 'c:\m\my_file.txt', 'off' )
% ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I]
% [drive:][path][filename] [/S [/D] [/L]]
%
% + Sets an attribute.
% - Clears an attribute.
% R Read-only file attribute.
%
% See also: fileattrib
narginchk( 2, 2 )
str = validatestring( action, {'on','off'} );
assert( exist( filespec, 'file' ) == 2 ...
, 'Pia:cmd_read_only:cannotFindFile' ...
, 'Cannot find file, "%s"' ...
, value2short( filespec ) )
if strcmp( str, 'on' )
dos_cmd = sprintf( 'attrib +R %s', filespec );
message = 'read-only: ON';
else
dos_cmd = sprintf( 'attrib -R %s', filespec );
message = 'read-only: OFF';
end
[ sts, msg ] = system( dos_cmd );
assert( sts == 0 ...
, 'Pia:cmd_read_only:FailedSetAttribute' ...
, 'Failed to set attribute: "%"' ...
, msg )
if nargout == 0
disp( message )
varargout = {};
elseif nargout == 1
varargout = { sts };
elseif nargout == 2
varargout = { sts, msg };
else
error('Wrong number of outputs')
end
참고 항목
카테고리
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!