"Input arguments for contour must be real.

I have an error in contourf function : "Input arguments for contour must be real. Use the function REAL to get the real part of the inputs."
I've checked the input file ,the data are all real numbers. Here's the code.
Thanks for your help .
[X, Y]=meshgrid(-5:0.1:5);
Z=cos(X).*cos(X).*log(Y);
C=contourf(X,Y,Z);
clabel(C)
grid on
figure
plot3(X,Y,Z);
hold on
grid on
xlabel('x');
ylabel('y');
title('Лінії рівня');
[res1,Fmin1]=fminsearch('f2',[-3.1,0.001])
plot3(res1(1),res1(2),Fmin1,'ro-');
[res2,Fmin2]=fminsearch('f2',[0.1,0.001])
plot3(res2(1),res2(2),Fmin2,'ro-');
[res3,Fmin3]=fminsearch('f2',[3.1,0.001])
plot3(res3(1),res3(2),Fmin3,'ro-');
figure
C=contourf(X,Y,Z);
clabel(C)
grid on
hold on
plot(res1(1),res1(2),'ro-');
plot(res2(1),res2(2),'ro-');
plot(res3(1),res3(2),'ro-');

 採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 7 日

0 投票

Y includes negative values. log() of negative is complex valued, so parts of your Z are complex valued. How would you like matlab to draw the contour of complex values?

2 件のコメント

Chen Liying
Chen Liying 2022 年 10 月 20 日
I have the same question, and i have checked my data, there had no negtive value, so I WONDER where is the complex values from? thank you !!
Walter Roberson
Walter Roberson 2022 年 10 月 20 日
Can you post (or attach) your code, and attach whatever data is needed to run it?

サインインしてコメントする。

その他の回答 (1 件)

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by