Effacer les filtres
Effacer les filtres

Copying the content of a Figure to another Figure

586 vues (au cours des 30 derniers jours)
HA
HA le 12 Fév 2019
Commenté : Walter Roberson le 14 Fév 2019
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 commentaires
HA
HA le 12 Fév 2019
@Jan, I think the question is clear. The code above is not doing what it should do i.e. copying the content of one figure to another.
Adam Danz
Adam Danz le 12 Fév 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.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 12 Fév 2019
Modifié(e) : Adam Danz le 13 Fév 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
  8 commentaires
Adam Danz
Adam Danz le 14 Fév 2019
Modifié(e) : Adam Danz le 14 Fév 2019
Interestingly, when I plot the (x,y) coordinates from the original plot onto a polar plot, it's just as distorted as when polaraxes() is used.
figure;
ax1Chil = ax1.Children;
ax2 = polar(ax1Chil.XData, ax1Chil.YData);
190214 090031-Figure 2.jpg
Walter Roberson
Walter Roberson le 14 Fév 2019
right because it is cartesian data , the polar plot converted to cartesian already .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Polar Plots dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by