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!