Copying the content of a Figure to another Figure
484 views (last 30 days)
Show older comments
Hi,
I am trying to copy the directivity pattern of an antenna array from the figure generated by the pattern command to another window but so far did not manage to do that.
I am using copyobj command but it does not work. Here is the code that I am executing to achieve this goal:
fc = 60.48e9; % Carrier Frequency in Hz.
numElements = 16; % Number of antenna elements.
prop = physconst('LightSpeed');
lambda = prop/fc;
% ULA Antenne Array Creation.
array = phased.ULA(numElements, lambda/2);
f1 = figure();
pattern(array, fc, -180:180, 0, 'PropagationSpeed',prop,...
'CoordinateSystem', 'polar',...
'Type', 'powerdb', 'Normalize', true);
ax1 = gca;
f2 = figure();
ax = axes;
ax2 = copyobj(ax1,ax);
I am doing that because I did not manage to find a way to solve the problem listed in this Question. Using the method above, I will copy the content of the figure to a polaraxes in UIFigure in Matlab App Designer.
Any solution to one of the mentioned problems is highly appreciated.
4 Comments
Adam Danz
on 12 Feb 2019
But Jan wants to know what you mean by "it does not work". For example, are you getting an error message or a warning message? Is the image appearing but with missing objects? Does the code freeze? This type of clarity gives us a starting point to come up with ideas for a solution. Once I ran the code myself, seeing the error message immediately guided me to the solution. Since you didn't inlude an error message, Jan rightfully asked for clarity.
Accepted Answer
Adam Danz
on 12 Feb 2019
Edited: Adam Danz
on 13 Feb 2019
The function copyobj(h,p) copies objects listed in h to a new parent, p. When your code is run, the error message indicates, "Axes cannot be a child of Axes." This is because you cannot assign one axis as a child to another axis. Rather, you should copy the axis to a new figure.
Here's the correct way to do that:
f2 = figure();
ax2 = copyobj(ax1,f2);
[UPDATE]
To copy objects from one set of axes to another, you must first get handles to all of the axis children and then copy that list of handles to an existing axis. Here's a demo that follows the code in your question.
% Get handles for all children from ax1
ax1Chil = ax1.Children;
% Copy all ax1 objects to axis 2
copyobj(ax1Chil, ax2)
In your case, even though the axes you're copying from are polar axes, the data are actually plotted in Cartesian coordinates. So you'll copy the objects to a cartesian plot (middle figure below).
ax1Chil = ax1.Children;
figure;
ax2 = axes;
copyobj(ax1Chil, ax2)
axis equal
rectangle('Position', [-50 -50, 100, 100], 'Curvature', [1,1]) %Example: add circle
If you add the object to a polar axis, the (x,y) coordinates create a completely different pattern (right figure below).
ax1Chil = ax1.Children;
figure;
ax2 = polaraxes('ThetaTick', -150:30:180, 'ThetaLim', [-180, 180]);
copyobj(ax1Chil, ax2)
The image below shows [original, Cartesian axes, polar axes].
![190213 095532-Figure 4.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/203965/190213%20095532-Figure%204.jpeg)
8 Comments
Walter Roberson
on 14 Feb 2019
right because it is cartesian data , the polar plot converted to cartesian already .
More Answers (0)
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!