필터 지우기
필터 지우기

Making a *.m file "read only."

조회 수: 18 (최근 30일)
Truman
Truman 2015년 2월 17일
편집: per isakson 2015년 2월 17일
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.

채택된 답변

Sean de Wolski
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.

추가 답변 (1개)

per isakson
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 CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by