How to subplot a graph returned by MATLAB function for which there is no option to take the figure handle as input nor can it return a handle as output?
3 次查看(过去 30 天)
显示 更早的评论
I would like to plot the output of cwt() to a subplot so that I can compare the result with other graphs next to each other. However, to the best of my understanding, cwt() doesn't take handles as input for me to pass a subplot handle. Nor does it return any handle. I tried a couple of approaches without much success. Ideally, I would like the approach to work something like:
Fs=100; t=0:1/Fs:10; y=sin(t); %create a simple sinusoidal signal
figure;
subplot(2,1,1);plot(t,Fs) %plot the sinusoidal signal in suplot 211
subplot(2,1,2);cwt(signal,Fs); %plot the output of cwt() in subplot of 212
But, that doesn't work. cwt() merely replaces the subplots and simply plots like normal.
I have tried other approaches such as copyobj():
figure(1); cwt(signal,Fs); ax1=gca
ax2=figure(2);
copyobj(ax1,ax2);
This works well in copying the figure from figure 1 to figure 2, but when i try a similar approach to copy figure 1 to subplot in figure 2, it fails giving me the error "Axes cannot be a child of Axes". Below the corresponding code:
figure(1); cwt(signal,Fs); ax1=gca
figure(2);ax2=subplot(2,1,1);
copyobj(ax1,ax2);
Any help?
1 个评论
回答(2 个)
Prajit T R
2018-4-9
Hi Hari
Here, cwt is being plotted as a subplot. Hence this should be possible in your case as well. Try to modify the code that you would find on the link to suit your requirement.
Hope this helps.
Cheers
0 个评论
Jan Rusz
2021-2-16
You have to copy ax1 to figure object, not to axes object:
fig2=figure(2);
copyobj(ax1,fig2);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!