MATLAB: Insert a string in a code to export a figure

insert a string in a code to export a figure

Hi,
This is code:
name='location';
options.Format = 'tiff';
hgexport(gcf, 'name.tif', options);
….
Can the 'location' be inserted to " name.tif" (replace 'name' by 'location')?
The exported filename is 'location.tif' (NOT 'name.tif').

Best Answer

Use sprintf or plain string concatenation to build your string:
hgexport(gcf, sprintf('%s.tif', name), options);
%or
hgexport(gcf, [name, '.tif'], options);