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!
0 个评论
采纳的回答
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)
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)
3 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!