How to enter variable names into plot title (R2019a)
93 ビュー (過去 30 日間)
古いコメントを表示
Nandakumar Unnikrishnan
2020 年 10 月 12 日
編集済み: madhan ravi
2020 年 10 月 12 日
Hello,
I am trying to enter a variable name into my plot title and it keeps failing. I have been looking up examples that have worked previously but I think that it is different in this version.
clc; clear all; close all;
x = -10:0.001:10;
% 2D Gaussian
m = [0 1 2 3 4 5]; s = [1 2 3];
for i = 1:5 %When the standard Deviation stays the same
p = (1/(s(1)*sqrt(2*pi))).*exp(-(x-m(i)).^2/(2*(s(1))^2));
figure (i);
plot(x,p);
title('2D Gaussian when mean is' m(i) ' and standard deviation is's(i));
end
This is the code that I have used right now. But Even when its not working. I even tried using [] to encapsulate the title and I tried using %f for the variables, but none of that seems to work. Does anyone have any advise for me?
Thank you
0 件のコメント
採用された回答
madhan ravi
2020 年 10 月 12 日
title(sprintf('2D Gaussian when mean is %.2f and standard deviation is %.2f', m(ii), s(ii)))
2 件のコメント
madhan ravi
2020 年 10 月 12 日
編集済み: madhan ravi
2020 年 10 月 12 日
title(sprintf('2D Gaussian when mean is %d and standard deviation is %d', m(i), s(1)));
その他の回答 (1 件)
Bruno Luong
2020 年 10 月 12 日
title("2D Gaussian when mean is " + m(i) + " and standard deviation is " + s(i))
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Title についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!