Problems in order to concatenate a string with file extension at filename parameter of imwrite
Mostrar comentarios más antiguos
Hi everyone,
i'm trying to save some images consecutively changing the filename of each one from a matrix which contains the parameters.
That is, the filenames would be: 'name_3_P1' 'name_4_P1' 'name_3_P2' 'name_4_P2'
where each parameter separated by '_' it's a position in that matrix.
Once I have obtained the string in a variable with the desired name, imwrite don't accept this string, because it forces me to add an extension. So, I'm looking for an alternativa for concatenating the string with the extension at the filename.
Any solutions? Thank you.
1 comentario
@Emilio: some comments:
- the imwrite documentation includes a list of supported image file formats, but .AVI is not listed.
- MATLAB does not distinguish between supplying the string directly as an argument or as a variable.
- Because the image file format is determined from the file extension, using a file name like 'name.avi_1_P1' will not work, as this is not a known file extension. This means your comment to Thorsten's answer "For example, it's not important if the string is 'name_3_P1' or 'name.avi_3_P1'." is incorrect.
There is nothing wrong with imwrite, it works perfectly following the syntax given in the documentation:
>> load spine
>> name = sprintf('temp_%d.png',3)
name =
temp_3.png
>> imwrite(X,map,name)
And here is the new image file shown in the Current Folder:

Respuestas (2)
Jan
el 28 de Mayo de 2015
There must be another problem. Please post the relevant part of the original code and the complete error message. Currently we have to guess too many details.
At least this works:
FileName = 'name_3_P1.png'
imwrite(rand(100, 100, 3), FileName)
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!