How do I plot 2 surf plots in different figures

조회 수: 3 (최근 30일)
Luis Landa Pulgar
Luis Landa Pulgar 2021년 4월 9일
편집: Cris LaPierre 2021년 4월 9일
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')

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 4월 9일
편집: Cris LaPierre 2021년 4월 9일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by