필터 지우기
필터 지우기

auto update of text in plot

조회 수: 2 (최근 30일)
rakesh kumar
rakesh kumar 2023년 12월 6일
답변: Dyuman Joshi 2023년 12월 6일
i have a plot for sigma =0.05. i want the text in the plot should display sigma = 0.03 when i change the value of sigma as 0.03 and save it as new png file as sigma=0.03
sigma=0.05
me3=rand(1,2000);
me3d=rand(1,2000);
X=1:2000
plot(X, me3, '-*', 'Color', 'red', 'LineWidth', 2, 'MarkerIndices', 1:1000:length(me1))
hold on
plot(X, me3d, '-*', 'Color', 'blue', 'LineWidth', 2, 'MarkerIndices', 1:1000:length(me1))
text(1000, 0.55, '\sigma = 0.05', 'FontSize', 14, 'FontWeight', 'bold')
ylabel(' eigen frequencies', 'FontWeight', 'bold', 'FontSize', 16)
xlabel('Sample size', 'FontWeight', 'bold', 'FontSize', 16)
set(gca, 'FontSize', 16, 'FontWeight', 'bold')
saveas(gcf, 'mean sigma = 0.05.png')
  댓글 수: 1
Mann Baidi
Mann Baidi 2023년 12월 6일
How are you planning to change the value of "sigma"?

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 12월 6일
Convert the script to a function (make appropriate change accordingly in doing so) and call the function for different values of sigma -
for sigma = [0.03 0.05]
myfun(sigma)
end
%Check the contents of the current folder
ls
'mean sigma = 0.03.png' 'mean sigma = 0.05.png'
%Function
function myfun(sigma)
me3=rand(1,2000);
me3d=rand(1,2000);
X=1:2000;
figure
plot(X, me3, '-*', 'Color', 'red', 'LineWidth', 2, 'MarkerIndices', 1:1000:length(me3))
hold on
plot(X, me3d, '-*', 'Color', 'blue', 'LineWidth', 2, 'MarkerIndices', 1:1000:length(me3))
text(1000, 0.55, sprintf('\\sigma = %0.2f', sigma), 'FontSize', 14, 'FontWeight', 'bold')
ylabel(' eigen frequencies', 'FontWeight', 'bold', 'FontSize', 16)
xlabel('Sample size', 'FontWeight', 'bold', 'FontSize', 16)
set(gca, 'FontSize', 16, 'FontWeight', 'bold')
saveas(gcf, sprintf('mean sigma = %0.2f.png', sigma))
end
Changes made -
Generalised the text to be displayed on the plot and filename of the image to be saved as, by including sprintf().

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by