Error using surf X,Y, Z and C cannot be complex
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (2)
Star Strider
il 25 Mar 2017
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.
vetri veeran
il 25 Mar 2017
0 voti
Categorie
Scopri di più su Performance and Memory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!