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

18 views (last 30 days)
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
for ss=0:1:50;
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));
b1=0.5* log(1+(4*T).^2) + 4*T*atan(1/(4*T));

Accepted Answer

Jakob B. Nielsen
Jakob B. Nielsen on 15 Jan 2020
Edited: Jakob B. Nielsen on 15 Jan 2020
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
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.
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.
Jakob B. Nielsen
Jakob B. Nielsen on 15 Jan 2020
Edited: Jakob B. Nielsen on 15 Jan 2020
You initialise s outside your for loop to be s=100, but then inside your loop you have:
Giving a new, permanent value to s. That is why your first iteration gives D(1) = 100, and the remaining goes completely bonkers :)

Sign in to comment.

More Answers (0)


Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by