Plotting A Matrix Using Surfc
2 次查看(过去 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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!