Plotting A Matrix Using Surfc

조회 수: 2 (최근 30일)
Brian Peoples
Brian Peoples 2019년 4월 24일
댓글: Walter Roberson 2019년 4월 25일
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에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by