Please help me this code.Here I'm getting a error and i wanna 3d plot from the code.

1 view (last 30 days)
clc
clear all
epsn_o=8.854*10^-12
H=0.6 %in meters
r=0.25 %in meters
A=(2*pi*r*H)+(pi*r*r)
B=0.03
for i=2:85
epsn_r(i)=i
for j=2:85
C(j)=j
h(i)=1/(epsn_r(i)-1)*(((C(j)*log(1.1388/0.03))/(2*3.1412*8.854*10^-12)) -0.6)
end
end
[epsn_r(i),C(j)]=meshgrid(epsn_r(i),C(j))
mesh(epsn_r(i),C(j),h(i))

Answers (1)

Walter Roberson
Walter Roberson on 1 Oct 2015
Have another look at your line
h(i)=1/(epsn_r(i)-1)*(((C(j)*log(1.1388/0.03))/(2*3.1412*8.854*10^-12)) -0.6)
it is inside "for i" "for j", so you are overwriting h(i) for every iteration of j. The result is going to be the same as if you had only written h(i) with the last value of j. It is unlikely that is what you want.
Your meshgrid() and mesh() calls are broken.
The third value you pass in to mesh() needs to be a 2D array which is length() of the first vector by length() of the second vector. You have h(i) as your third value, indicating that you are thinking of h as being something that has one value for each combination of epsn_r and C values. You would need to be writing to a two dimension matrix inside your loops for that to work. For example if your loop was assigning to h(i,j) instead of to h(i)
Once you have h as a 2D array, then you should be able to skip the meshgrid() call and use
mesh(epsn_r, C, h)
but you might need
mesh(epsn_r, C, h.')

Tags

Community Treasure Hunt

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

Start Hunting!