Contour a log fuction with n contour levels

I would like to create a contour of a log function with a multiple contour levels, but when N is included the figure turns out blank, the following is an example:
[i,j] = meshgrid(-50:1:50,-50:1:50);
for x=1:size(i,1)
for y=1:size(j,1)
R(x,y) = log(i(x,y)*j(x,y));
end
end
contour(R,10);

답변 (1개)

Honglei Chen
Honglei Chen 2012년 4월 16일

0 개 추천

There are negative numbers in log so the result may be complex. In addition, there is zero in log, so log(0) gives infinity, which cannot be dealt by contour. Are you sure you want log on such ranges?
BTW, you could have written
R = log(i.*j);
to save the two loops.

댓글 수: 3

Richard Brown
Richard Brown 2012년 4월 16일
or even better R = log(i .* j)
(no loops)
Jhon
Jhon 2012년 4월 16일
actually no, i can manage the range to be strictly higher than 0
Guo
Guo 2012년 4월 16일
I agree with Richard,Matrix computation is the dominant feature of matlab.Matlab canbe more efficient in this form.

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

카테고리

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

태그

질문:

2012년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by