Problem with figures, plots behave oddly and are unusable

Hello,
I have been observing a problem related to all kinds of functions which plot something (plot, surf, contour etc). For example the following code results in a very distorted image
f=@(x) [x(1)^2-4*x(2)^2+3; x(1)-x(2)^2];
figure(1)
plotzeros(f, [-0.5 4], [-2.2 2.2])
Screenshot (196).png
Ihave tried to uninstall and reinstall MATLAB, however nothing has changed. What should I do to solve the problem?
Thank you.

6 Comments

Can you provide a different example? I have never heard of a plotzeros function and have no clue what it might be doing.
Maybe also explain what you are trying to plot - you have 2 inputs and 2 outputs of your function. I would actually expect multiple lines from that (if you want a line plot).
I am sorry, I thought plotzeros was a built in function but I actually got it from my professor.
The function plots the zeros of bivariate functions, through the contour function.Here's the code:
function plotzeros(fun, x_limits, y_limits, varargin)
plotzeros(fun, [X_MIN X_MAX], [Y_MIN Y_MAX], sample_len)
if nargin > 3
sample_len = varargin{1};
else
sample_len = 500;
end
v_dis_x = linspace(x_limits(1), x_limits(2), sample_len);
v_dis_y = linspace(y_limits(1), y_limits(2), sample_len);
n_dis_x = length(v_dis_x);
n_dis_y = length(v_dis_y);
Z_1 = zeros(n_dis_y, n_dis_x);
Z_2 = zeros(n_dis_y, n_dis_x);
for i = 1:n_dis_x
for j = 1:n_dis_y
funz = fun([v_dis_x(i); v_dis_y(j)]);
Z_1(j,i) = funz(1);
Z_2(j,i) = funz(2);
end
end
contour(v_dis_x, v_dis_y, Z_1, [0 0], 'Linecolor',[0 1 0], 'Linewidth', 2)
hold on
contour(v_dis_x, v_dis_y, Z_2, [0 0], 'Linecolor',[0 0 1], 'Linewidth', 2)
axis equal
set(gca, 'FontSize', 14)
grid on
end
Anyway, another example:
v1=([4 3]/5)'; v2=([-3 4]/5)';
l1=5; l2=10;
V = [v1,v2];
D1 = diag([l1,l2]);
A1 = V*D1*V';
l1=1; l2=10;
D2 = diag([l1,l2]);
A2 = V*D2*V';
b=[4 8]';
%so far we just created matrixes and vectors
x=linspace(-10,10,80); y=linspace(-10,10,80);
[X,Y]=meshgrid(x,y);
Phi1 = 0.5* ( A1(1,1)*X.^2 + A1(2,2)*Y.^2 + 2*A1(1,2)*X.*Y ) - b(1)*X - b(2)*Y;
Phi2 = 0.5* ( A2(1,1)*X.^2 + A2(2,2)*Y.^2 + 2*A2(1,2)*X.*Y ) - b(1)*X - b(2)*Y;
surf(X,Y,Phi1,'Lines','no'); title('phi 1'); hold on
contour(X,Y,Phi1,20)
Screenshot (197).png
And this is the resulting plot
Look HERE
Maybe it has something to do with this
Thank you very much!
Indeed the problem was with the driver of the graphic card, so the command
opengl software
put figures back to normal.
Thanks Valentina! I really love the image in the question. It is one of the best Matlab diagrams I've ever seen! :-)
It looks like it was made with the Jackson Pollock toolbox.

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2019a

Asked:

on 11 Sep 2019

Edited:

on 11 Sep 2019

Community Treasure Hunt

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

Start Hunting!