New file name with multiple variables
Mostrar comentarios más antiguos
So I made a code in Matlab and i want to save my file with a custom name. But for some reason I can't seem to be able to add multiple variables to the name. This is the code that I have. What am I doing wrong?
baseFileName = [name,'_Freesbeeld','D',R,'H',Height,'Dpi',dpi,'.tif'];
%If I use the example below it works
%baseFileName = [name,'_Freesbeeld','.tif'];
fullFileName = fullfile(savelocation, baseFileName);
imwrite(W, fullFileName); % img respresents input image.
Respuesta aceptada
Más respuestas (1)
"What am I doing wrong?"
MATLAB does not implicitly convert the numeric dpi to the string that represents that number, it converts the numeric to the character with that character code, e.g. 1 -> char(1). It is unlikely that this is what you intended, so you need to do the conversion explicitly yourself, e.g. using num2str or int2str as Tom Osborne suggested, or even better by using sprintf to define the whole filename in one go:
baseFileName = sprintf('%s_Freesbeeld_D%d_H%d_Dpi%d.tif',name,R,Height,dpi)
You will have to check that he format string is correct for your data types, as you did not tell us anything about them.
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!