auto update of text in plot
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
rakesh kumar
am 6 Dez. 2023
Beantwortet: Dyuman Joshi
am 6 Dez. 2023
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 Kommentar
Akzeptierte Antwort
Dyuman Joshi
am 6 Dez. 2023
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
%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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!