my code is running but it doesnt show the exponential graph .it shows nothing at the graph.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
arif hussain
le 14 Juin 2017
Modifié(e) : arif hussain
le 15 Juin 2017
filename = 'datacollect2.xlsx';
num = xlsread(filename,'B1:B60');
w = num/60;
N = length(num);
t = 1/w;
s = xlsread(filename,'B3:B3');
xt= s;
g = 1/N;
i = xt + num;
h = xt/ i ;
ln=@log;
q=ln(h);
zeta = g * q;
j= 1-power(zeta,2);
wd = w*power(j,1/2);
r = bsxfun(@rdivide,w,wd);
k = zeta*r;
l=sin(wd);
u=k*l;
m=bsxfun(@plus,cos(wd),u);
n= - zeta*w;
plot (1 - exp(n)*(m))
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Juin 2017
You are using the / operator in several places. In MATLAB, A/B is more or less the same as A * pinv(B) . 1/w where w is 60 x 1, gives you a 1 x 60 result. Likewise, h = xt/ i where i is 60 x 1, gives you a 1 x 60 result. You then end up working with this mix of 60 x 1 and 1 x 60 and you end up with trying to combine arrays in the wrong way.
>> 1/[2;4;3]
ans =
0 0.25 0
Notice the output is a row vector for a column vector divisor.
If you would need the answer [0.5; 0.25; 0.3333] (column vector, individual divisions) instead for this calculation, then you need to use the ./ operator
Because of this, in your
h = xt/ i ;
most of the entries will be 0. When you have A/B with scalar A and column vector B, the result turns out to always be a row vector where each entry is 0 except for the single entry located where B first reaches its largest absolute magnitude, [~, idx] = max(abs(B)), and that one location of the result is 1./B(idx) .
With all of those 0 floating around in h, ln(h) is mostly -inf . Then when you start doing more matrix multiplications on the matrices with -inf you end up with situations where you have (-inf) - (-inf) which is NaN. So your output matrix m comes out all NaN. Then there are no non-NaN entries for the plotting to work on.
It is almost certain that you should be mostly using ./ operators instead of / operators . If you are absolutely sure that you want / operators then you should comment those lines and you should comment the purpose of your code and the methods, as otherwise people like me are going to come along and assume that your code is broken.
1 commentaire
Plus de réponses (1)
Matt J
le 14 Juin 2017
Inspect the plotted expression from the command line.
>> disp( 1 - exp(n)*(m) )
Maybe it doesn't contain anything that can be plotted.
0 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!