Reputation: 172
I want to ask quite simple question. I'm writing function converting raw image to bmp. Function name is raw2bmp()
Now say I want to work with file LENA.raw
so I type my function raw2bmp('LENA.raw')
. My function produces output bmp image. I want it name LENA.raw.bmp
. So the question is how to get file name as an array of symbols?
Upvotes: 1
Views: 268
Reputation: 187
function raw2bmp(name)
fid=fopen(name);
rawdata=fread(fid);
%do the conversion of rawdata and save it to bmpdata
newname=[name '.bmp'];
imwrite(bmpdata,newname,'bmp');
end
Then you call the function
raw2bmp('LENA.raw')
which saves the bmp image under 'LENA.raw.bmp'
Upvotes: 2
Reputation: 172
I already found an answer. Maybe it will be useful for someone
function [ img1 ] = raw2bmp( in_file );
out_name = [in_file '.bmp'];
Upvotes: 0
Reputation: 50717
You can use sprintf()
to format your string, like this:
file_to_save = sprintf('%s.bmp', input_file);
Then you can save the result to file_to_save
.
Upvotes: 2