Imwrite with changing title

7 ビュー (過去 30 日間)
Oliver Horrobin
Oliver Horrobin 2021 年 2 月 3 日
コメント済み: Oliver Horrobin 2021 年 2 月 5 日
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

採用された回答

yanqi liu
yanqi liu 2021 年 2 月 5 日
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 件のコメント
Oliver Horrobin
Oliver Horrobin 2021 年 2 月 5 日
Perfect!
Thanks a bunch

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by