plot function in predesigned figure

1 次查看(过去 30 天)
Hello!
tryscript is my script, tryyy is my desired function and f_vorlage is where I define h. h is the in f_vorlage predesigned graph I want to put my function x in.
But, it doesnt work. As soon as tryyy plots x it sort of deletes h?
I want to plot x in my predesigned h.
How do I do this?
Thank you for the support!

采纳的回答

Asad Mirza
Asad Mirza 2019-2-23
编辑:Asad Mirza 2019-2-23
Perhaps use hold on?
h=figure(1);
hold on
f_vorlage(h)
tryyy(h)
In addition in your tryyy.m have it grab the current plot handle with gca
function tryyy(fig)
h=gca
ax = findobj(h, 'type', 'axes');
if isempty(ax)
error('Your figure does not have any existing axes')
end
if length(ax) > 1
error('Your figure has more than one axes')
end
x=[52.23;52.45;56.32;55.48;56.32;53.39;55.53;53.67;57.89]
x=x'
plot(x)
untitled.jpg
Using a random set of values it looks like it plots properly
function tryyy(fig)
h=gca
ax = findobj(h, 'type', 'axes');
if isempty(ax)
error('Your figure does not have any existing axes')
end
if length(ax) > 1
error('Your figure has more than one axes')
end
x=200*rand(1,10000)-50;
plot(x)
untitled2.jpg
  3 个评论
Asad Mirza
Asad Mirza 2019-2-23
It should work but I suspect that because your y scale stops at 200 you cannot see the rest of the graph.
axis auto
Should fix your scaling issue but you'd have to figure out a way to fix your nice grid to change depending on the largest data point you're plotting.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by