Plotting A Matrix Using Surfc

2 visualizaciones (últimos 30 días)
Brian Peoples
Brian Peoples el 24 de Abr. de 2019
Comentada: Walter Roberson el 25 de Abr. de 2019
Hello--
I am struggling an recieivng an error when I try to plot a matrix using surfc (in a function). I was wondering if anybody knew why.
My input for N is 10.
function lake = MakeLake_BDP(N)
lake = zeros(N,N);
lake(1,:) = -999;
lake(N,:) = -999;
lake(:,1) = -999;
lake(:,N) = -999;
%randn where the dist has a mean of 4 and sd of 2
lake(2:N-1,2:N-1) = 4 + 2.*randn(N-2);
T = lake;
w = .175; %weighing factor
for k = 1:15
T(1,:,k+1) = -999;
T(N,:,k+1) = -999;
T(:,1,k+1) = -999;
T(:,N,k+1) = -999;
for i = 2:N-1
for j = 2:N-1
[open] = Isopen(i,j,N);
M = sum(open);
T(i,j,k+1) = T(i,j,k)*(1-w)+w/M*([T(i-1,j,k),T(i+1,j,k),T(i,j-1,k),T(i,j+1,k)]*open);
end
end
end
lake = T; %sets lake equal to T
%plotting
surfc(lake);
end
function [open] = Isopen(row,col,N)
%initialize open
open = ones(4,1);
%row and col values/concention for directions
%if statement
if row == 2
open(1,1) = 0; %up
elseif row == N-1
open(2,1) = 0; %down
elseif col == 2
open(3,1) = 0; %left
elseif col == N-1
open(4,1) = 0; %right
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Abr. de 2019
Your T is created as 3 dimensional. You are trying to surfc() a 3D volume. surfc() and surf() are only for 2D arrays (on a plane that might be warped.)
You can use isosurface() or you can use slice(). Or you can use the volumeViewer() app. Or you can use vol3d v2 from the File Exchange.
  2 comentarios
Brian Peoples
Brian Peoples el 25 de Abr. de 2019
My homerwork says:
  1. Plot the surface of lake using a 3-D contour plot. Comment on how it looks at the bottom of your main function before your subfunction. Use the surfc function to make this plot.
Are you sure this cannot be used?
Walter Roberson
Walter Roberson el 25 de Abr. de 2019
I am certain that you cannot use surfc() to plot all of T in one call.
What I do not know is what relationship T has to the surface of a lake.
For example I could hypothesize that T(:,:,end) might represent the surface of a lake, and that you might surfc() that .

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by