How do I use two different matlab scripts to plot the figure using subplot?
6 次查看(过去 30 天)
显示 更早的评论
I have two different matlab scripts that works on different directory which plots the different figures from each script. I don't have any function on both scripts. What I want to do is say I plot first figure from first matlab script than I want to plot next figure from second figure side by side (like subplot function) and so on. Is there any idea we can do like this? let me know any suggestions.
0 个评论
回答(1 个)
Star Strider
2017-2-9
Try this:
figure(1);
plot(1:10, rand(1,10), '-b');
hax1 = gca;
figure(2)
plot(1:20, rand(1,20), '-pr');
hax2 = gca;
f3 = figure(3)
subplot(1,2,1,copyobj(hax1,f3))
subplot(1,2,2,copyobj(hax2,f3))
The figure(3) object will have the plots from the first two figures as subplots. See the documentation for subplot for a full explanation and additional options.
Note that your functions will have to return the axes handles (here ‘hax1’ and ‘hax2’) as outputs so you can use them in the subplots.
Experiment with your code to get the result you want.
2 个评论
Gayan Lankeshwara
2020-5-18
Hi there,
Could you please suggest me whether this approach will work ?
Can we save hax1 and hax2 workspace variables as .mat and load in the new script file and use it to plot the following ?
load hax1.mat
load hax2.mat
hax1 = hax1 ;
hax2 = hax2 ;
f3 = figure(3)
subplot(1,2,1,copyobj(hax1,f3))
subplot(1,2,2,copyobj(hax2,f3))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!