Reputation: 679
I want to save a matlab source code into a string format in matlab. Does anyone know how to do this? For example,
type xxx.m
can display the source code of xxx.m. Then using what command am I able to save it into a string?
Upvotes: 1
Views: 460
Reputation: 32930
Two approaches to this that I can think of are:
Storing the output of type filename
into a string using evalc
, for example:
str = evalc('type filename');
Directly reading the file and storing its contents into a string, for instance:
C = textread(filename, '%s', 'delimiter', '');
str = sprintf('%s\n', C{:});
There are, of course, alternative ways of doing this with textscan
, fgets
, fgetl
, etc...
The resulting str
should now hold the contents of your file.
Upvotes: 3
Reputation: 2524
fid=fopen('filename.whatever','r')
txt=fread(fid,'uint8=>char')' %note the transpose!
Upvotes: 0