Imwrite with changing title

5 vues (au cours des 30 derniers jours)
Oliver Horrobin
Oliver Horrobin le 3 Fév 2021
Commenté : Oliver Horrobin le 5 Fév 2021
Hi there, I am looking for help with using the imwrite function.
I have a string that changes when I put different values in the function.
[xCentroid,yCentroid]= Centroid(Beam)
ImLabel = sprintf("a= %.2f,b= %.2f,x= %.2f,y= %.2f,xBar= %.2f,yBar= %.2f,amplitude= %.2f,xCentroid: %.2f, yCentroid: %.2f",a,b,x,y,xBar,yBar,amplitude,xCentroid,yCentroid)
This creates this string: "a= 70.00,b= 10.00,x= 300.00,y= 300.00,xBar= 150.00,yBar= 150.00,amplitude= 250.00,xCentroid: 149.32, yCentroid: 150.18"
The numbers change how I want them to.
How do I have it so that whenever I run the program it saves in a folder? I have tried adding .jpg to the end of this string. No changes.
The rest of the code is as follows:
img = getframe(gcf);
fullFileName = fullfile(folder,ImLabel);
imwrite(img.cdata,fullFileName,'jpg')
At the moment it doesnt work unless I change ImLabel to something simple eg 'Test.jpg'.
Cheers,
Ollie

Réponse acceptée

yanqi liu
yanqi liu le 5 Fév 2021
use
ImLabel = sprintf("a=%.2f_b=%.2f_x=%.2f_y=%.2f_xBar=%.2f_yBar=%.2f_amplitude=%.2f_xCentroid=%.2f_ yCentroid=%.2f",a,b,x,y,xBar,yBar,amplitude,xCentroid,yCentroid)
  1 commentaire
Oliver Horrobin
Oliver Horrobin le 5 Fév 2021
Perfect!
Thanks a bunch

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by