How can I prevent MATLAB from plotting an object and it's transformation? I am trying to rotate a surface and am using a transformation matrix to do it, but I don't want the surface to be plotted at any point, How can I stop it?
% Defines the input variables for the SC at the orbital point.
FoV = deg2rad(FoV);
dist = sqrt(xp^2 + yp^2 + zp^2);
xp = 168.820350140000;
yp = 22703.2636668300
zp = 40331.2908433900
% Generates a line from the orbit point to the centre of the Earth.
xl = linspace(0,xp);
yl = linspace(0,yp);
zl = linspace(0,zp);
% Plots the orbits, orbit point, and Earth object onto the same plot.
plot3(xl,yl,zl);
hold on
scatter3(xp,yp,zp,100,'x','blue')
% Creates a cone for the FoV of the SC that targets the Earth's centre.
[x,y,z] = cylinder([dist*tan(FoV) 0],100);
h = surface(y,dist*z,x);
t = hgtransform('Parent',ax);
set(h,'Parent',t);
x_temp = get(h,'xdata');y_temp = get(h,'ydata');z_temp = get(h,'zdata'); % Duplicates data.
% Determines the coordinate rotations needed to align the cone with the
% orbit point and transforms the cone using object R.
% This if loop calibrates the cone for the 4 quadrants of 2 tangents.
xa = atan(yp/xp);
za = atan(zp/sqrt(xp^2+yp^2));
if xp>0
xa = xa-pi/2;
else
xa = xa+pi/2;
end
R = makehgtform('zrotate',xa,'xrotate',za);
set(t,'Matrix',R);
% Performs the same numerical transformation of the duplicate data and
% creates a sew sets of coordinates that match the transformation.
for i = 1:101
new_first_row(i,:) = (R * [x_temp(1,i);y_temp(1,i);z_temp(1,i);1])';
new_second_row(i,:) = (R * [x_temp(2,i);y_temp(2,i);z_temp(2,i);1])';
end
xr = new_first_row(:,1)'; % Transformed x data.
xr(2,:) = new_second_row(:,1)';
yr = new_first_row(:,2)'; % Transformed y data.
yr(2,:) = new_second_row(:,2)';
zr = new_first_row(:,3)'; % Transformed z data.
zr(2,:) = new_second_row(:,3)';
I want xr
, yr
, and zr
to be calculated, but don't want any plots to be created from this specific script. I later want to create a different plot using this data. If there are any other ways of doing this, please let me know.
As Ander Biguri already said, there are probably better ways than to cram a round peg into a square hole.
As to the question itself: figure visibility is controlled through figure('Visible', 'off')
, where 'on'
is obviously the default. Don't forget to close your figure though:
fig = figure('Visible', 'off'); % Create invisible figure with handle
h = surface(...); % Your plot
% (...) your other processing
close(fig); % Close figure to save RAM