How do I plot 2 surf plots in different figures

3 Ansichten (letzte 30 Tage)
Luis Landa Pulgar
Luis Landa Pulgar am 9 Apr. 2021
Bearbeitet: Cris LaPierre am 9 Apr. 2021
Hi,
I am trying to plot 2 different surf plots, however when I plot the second one it overwrites the first one. I need them both to be outputed as two separate figures. I have tried to use the figure command but it does not work, it keeps overwriting. Also, if use figure(1) and figure(2), it says that for figure(2) "Index exceeds the number of array elements (1)."
Here is what I have:
x = -2:0.1:2;
y = -2:0.1:2;
[x,y] = meshgrid(x, y);
U = (x.^2+y.^2).^0.5;
V = 4*del2(U);
figure
surf(x,y,U)
xlabel('x');ylabel('y');
title('Function Plot z = (x^2 + y^2)^0.5');
figure
surf(x,y,V)
figure;
xlabel('x');ylabel('y');
title('Laplacian Plot')

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 9 Apr. 2021
Bearbeitet: Cris LaPierre am 9 Apr. 2021
The code you have shared appears to work fine. You do have an extra figure; command that you don't need (after the second surf command).
x = -2:0.1:2;
y = -2:0.1:2;
[x,y] = meshgrid(x, y);
U = (x.^2+y.^2).^0.5;
V = 4*del2(U);
figure
surf(x,y,U)
xlabel('x');ylabel('y');
title('Function Plot z = (x^2 + y^2)^0.5');
figure
surf(x,y,V)
xlabel('x');ylabel('y');
title('Laplacian Plot')
The error about index exceeding array elements suggests that you have probably accidentally created a variable figure that has now taken precedence over MATLAB's function figure. Clear your workspace and try again. If it continues to happen, inspect the rest of your code for anywhere where you assign figure a value.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by