Borrar filtros
Borrar filtros

Copying the content of a Figure to another Figure

586 visualizaciones (últimos 30 días)
HA
HA el 12 de Feb. de 2019
Comentada: Walter Roberson el 14 de Feb. de 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 comentarios
HA
HA el 12 de Feb. de 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 el 12 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 12 de Feb. de 2019
Editada: Adam Danz el 13 de Feb. de 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 comentarios
Adam Danz
Adam Danz el 14 de Feb. de 2019
Editada: Adam Danz el 14 de Feb. de 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 el 14 de Feb. de 2019
right because it is cartesian data , the polar plot converted to cartesian already .

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polar Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by