input function as plot title?
6 次查看(过去 30 天)
显示 更早的评论
im creating a function that plots a user input function. i want the title to be just the function entered, but when i run the code, it displays the whole long vector that the function outputs.
fh=input('Enter a function: ');
minimum=min(fh)
maximum=max(fh)
plot(x,fh)
axis([a b floor(minimum) ceil(maximum)])
title(sprintf('%s',fh))
for example, if i input x^2 as the function, the graph would use 0 4 9 16 etc. as the title rather than just x^2.
0 个评论
采纳的回答
更多回答(1 个)
Johannes Hougaard
2020-4-23
I think this would do it
function_name = input('Enter a function:','s');
fh = str2func(strcat('@(x)',function_name));
fplot(fh,[min(x) max(x)]);
title(sprintf('%s',strrep(function_name,'.','')))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!