Imwrite with changing title

조회 수: 1 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by