Error using surf X,Y, Z and C cannot be complex
조회 수: 41 (최근 30일)
이전 댓글 표시
Hi all,
I want to draw 3D plot using surf command for vt = 0, -0.1...-0.5
I am getting an error as,
Error using surf X,Y, Z and C cannot be complex
My code is given below,
B = 1e-4; sigma_on = 0.45; x_on = 0.06; sigma_p = 4e-5; A = 1e-10; sigma_off = 0.013; x_off = 0.4; G_m = 0.025; rho = 1e-3; v_m = -0.5;
vt= 0:0.1:0.5;
t = 0.01:0.01:1;
for v = 1:length(vt)
v_m = -vt(v);
for x = 1:length(t)
G(x) = G_m*t(x)+ exp(sqrt(v_m));
f1(x) = A*sinh(v_m/sigma_off)*exp(-(x_off^2/t(x)^2));
f2(x) = B*sinh(v_m/sigma_on)*exp(-(t(x)^2/x_on^2));
f(x) = f1(x) + f2(x);
final(v,x)=log(f(x));
end
end;
surf(t,vt,final);
Can anyone help me.
댓글 수: 0
채택된 답변
Jan
2017년 3월 25일
편집: Steven Lord
2017년 3월 25일
The error message is clear: "X,Y, Z and C cannot be complex". Obviously there are complex values. All we see is the failing code, but we cannot guess reliably, what its intention is. Therefore it is hard (or random) to suggest an improvement.
Maybe you want:
surf(t, vt, real(final));
or
surf(t, vt, abs(final));
or your calculations are wrong.
[SL: fixed typo in last code segment.]
추가 답변 (2개)
Star Strider
2017년 3월 25일
The logarithm of a negative number will be complex. There are several ways to avoid that, the easiest being:
final(v,x)=log(abs(f(x)));
Note that the logarithm of 0 is -Inf, so you may want to trap ‘f(x)’ to prevent it from being zero as well. The easiest way to do that would be to have it equal NaN if it is zero, because NaN values will not plot. Consider setting the negative values of ‘f(x)’ to NaN as well, as one option.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!