Plotting A Matrix Using Surfc

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2019-4-25
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 个评论
Brian Peoples
Brian Peoples 2019-4-25
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 2019-4-25
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 .

请先登录,再进行评论。

更多回答(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