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 Ansichten (letzte 30 Tage)
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?

Antworten (2)

Prajit T R
Prajit T R am 9 Apr. 2018
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

Jan Rusz
Jan Rusz am 16 Feb. 2021
You have to copy ax1 to figure object, not to axes object:
fig2=figure(2);
copyobj(ax1,fig2);

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by