What is going wrong with my mesh command?

I am trying to visualize this function and eventually its contour lines:
clear all
[x,y]=meshgrid(-10:0.1:10)
d=max([sqrt(x.^2+y.^2);sqrt((x-5).^2+(y+1).^2);sqrt((x-4).^2+(y-6).^2);...
sqrt((x-1).^2+(y-3).^2)])+eps;
mesh(d)
I get an error message saying Z should be a matrix. I looked at the example here http://www.mathworks.com/help/matlab/ref/mesh.html, and I don't understand why their function generates a matrix and mine don't. Altough mine is a 'weird' function with a max it shouldn't be conceptually too different, what am I missing here?

 채택된 답변

Iman Ansari
Iman Ansari 2013년 5월 6일
편집: Iman Ansari 2013년 5월 6일

0 개 추천

Hi.
clear
[x,y]=meshgrid(-10:0.1:10)
d=max(sqrt(x.^2+y.^2),sqrt((x-5).^2+(y+1).^2));
d=max(d,sqrt((x-4).^2+(y-6).^2));
d=max(d,sqrt((x-1).^2+(y-3).^2))+eps;
mesh(x,y,d)
OR
meshc(x,y,d)

댓글 수: 2

Gian Lorenzo
Gian Lorenzo 2013년 5월 6일
Thanks! Can you explain me what's the wrong reasoning I am doing here? Does the max function handles at most two arguments? Is eps strictly necessary?
Iman Ansari
Iman Ansari 2013년 5월 6일
편집: Iman Ansari 2013년 5월 6일
From Help: If A is a matrix, max(A) treats the columns of A as vectors, returning a row vector containing the maximum element from each column.
Your input in max function is 804*201, so output become 1*201.
No.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 5월 6일

1 개 추천

d=max( cat(3, sqrt(x.^2+y.^2), sqrt((x-5).^2+(y+1).^2), sqrt((x-4).^2+(y-6).^2), sqrt((x-1).^2+(y-3).^2)), 3) + eps;

댓글 수: 1

Gian Lorenzo
Gian Lorenzo 2013년 5월 6일
Never seen this cat function, very interesting, thank you

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by