1
votes

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?

3

3 Answers

2
votes

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.

2
votes
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'

0
votes

I already found an answer. Maybe it will be useful for someone

function [ img1 ] = raw2bmp( in_file );

out_name = [in_file '.bmp'];