how to store value computed from into array and plot the value in graph

6 次查看(过去 30 天)
In given code the value ss has to be incremented from 0 to n values and to be stored as variable.
and for every value of ss the value of a4 and b3 need to be caluclated and stored as variable.
at last the plot must be drawn between SS vs A4 and B3.
Could anyone please sugesst some to idea to it?????
w=100 %land subsection width
s=100 %Edge to edge separation
h=62 %dielectric thickness
er=4.7; %Dieelctric Constant
vo=3e8;
pi=3.14;
for ss=0:1:50;
e0=8.85e12;
T=h/ss;
D=s/ss;
a1=(ss/(2*pi*e0));
a2=0.5*(2*D-1)*log(2*D-1) - (2*D-1)*log(2D+1) - 0.5*(2*D-1)*log((2*D-1).^2 + (4*T).^2) + 0.5*(2*D-1)*log((2*D-1).^2 + (4*T).^2) + T*(atan((2*D+1)/4*T)- atan((2*D-1)/4*T));
a3=a1*a2;
b1=0.5* log(1+(4*T).^2) + 4*T*atan(1/(4*T));
b2=a1*b1;
a4=abs(a3)
b3=abs(b2)
end

采纳的回答

Jakob B. Nielsen
Jakob B. Nielsen 2020-1-15
编辑:Jakob B. Nielsen 2020-1-15
Issue 1 is that your first loop iteration sees ss=0, and then you have s/ss... Can't divide by 0! :)
Aside from that, you simply need to use indexing. Let me give you an example here, and you can easily apply that to your code.
for ss=1:51 %you dont need to specify steps of 1 - only specify steps if they are different from 1 :)
ss_save(ss)=ss; %save the iteration number
a4(ss)=ss*2; %just some simple example math
b3(ss)=a4(ss)*1.2;
end
plot(ss_save,a4);
hold on %hold on makes the 2nd plot appear in the same window as the first plot. If you dont want this, use hold off instead.
plot(ss_save,b3);
Your result will be (in this example) two vectors named ss_save and a4, both with dimension 1x51 and each index will have that loop iterations value. So a4(17) will have the 17th loop iteration value. You cannot index 0s though, so your for loop cant be for ss=0:50.
(Side info; you can, in a simple case like this, also simply initialise your "ss_save" vector before (or even after) the for loop - but doing it within the loop is just fine too, and gives you more flexibility.
ss_save=1:1:51;
  2 个评论
Venkatkumar M
Venkatkumar M 2020-1-15
clc
clear all
w=100 %lanD subsection wiDth
s=100 %EDge to eDge separation
h=62 %Dielectric thickness
er=4.7; %Dielctric Constant
vo=3e8;
pi=3.14;
for ss=1:1:50
e0=8.854e-12;
T(ss)=h/ss;
D(ss)=s/ss;
s=2*pi*e0;
a1(ss)=(ss/(s));
a2(ss)=0.5*(2*D(ss)-1)*log(2*D(ss)-1) - (2*D(ss)-1)*log(2.*D(ss)+1) - 0.5*(2*D(ss)-1)*log((2*D(ss)-1).^2 + (4*T(ss)).^2) + 0.5*(2*D(ss)-1)*log((2*D(ss)-1).^2 + (4*T(ss)).^2) + T(ss)*(atan((2*D(ss)+1)/4*T(ss))- atan((2*D(ss)-1)/4*T(ss)));
a3(ss)=a1(ss)*a2(ss);
b1(ss)=0.5* log(1+(4*T(ss)).^2) + 4*T(ss)*atan(1/(4*T(ss)));
b2(ss)=a1(ss)*b1(ss);
a4=abs(a3);
b3=abs(b2);
ss_save(ss)=ss; %save the iteration number
a4(ss)=abs(a3(ss)); %just some simple example math
b3(ss)=abs(b2(ss));
end
plot(ss_save,a4,'b');
hold on
plot(ss_save,b3,'r');
Given code value ouput of D(ss) should 100,50,33.33,25,20,16.6 and etc
but value of D(ss) is totally different 100,2.78015600000000e-11,1.85343733333333e-11,1.39007800000000e-11.... and etc
may i know why the value is gattting changed?
Jakob B. Nielsen
Jakob B. Nielsen 2020-1-15
编辑:Jakob B. Nielsen 2020-1-15
You initialise s outside your for loop to be s=100, but then inside your loop you have:
D(ss)=s/ss;
s=2*pi*e0;
Giving a new, permanent value to s. That is why your first iteration gives D(1) = 100, and the remaining goes completely bonkers :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

产品


版本

R11.1

Community Treasure Hunt

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

Start Hunting!

Translated by