1

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 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I just posted easier way. Sorry to bother.
@MykolaServetnyk I prefer to use sprintf(), especially when I want my file name like file_0005.bmp, then I can simply use sprintf('file_%04d.bmp', 5).
2
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'

Comments

0

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

function [ img1 ] = raw2bmp( in_file );

out_name = [in_file '.bmp'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.