Matlab isn't ploting the function
Afficher commentaires plus anciens
Hi everyone!
I'm trying to get Matlab to fetch the values of an excel cell in a particular sheet in a particular workbook, then computing a piecewise function and then presenting the results in a logarithmic scale. All fine and cool but then, when the graph shows up, nothing is on it.
I'm very very new to Matlab (like two days new) and i've been strugling with it. Any help?
eta_l = xlsread('calculos.xlsx','Theoretical Predictions','S2');
eta_0 = xlsread('calculos.xlsx','Theoretical Predictions','S2');
l_c = xlsread('calculos.xlsx','Theoretical Predictions','P3');
sigma_f = xlsread('calculos.xlsx','Base Values','B3');
v_f = xlsread('calculos.xlsx','Burn','E23');
E_m = xlsread('calculos.xlsx','Base Values','D2');
E_f = xlsread('calculos.xlsx','Base Values','B2');
d = xlsread('calculos.xlsx','Base Values','B5');
for x=logspace(-6,2)
if x < l_c
y1=((eta_l.*eta_0.*((v_f.*sigma_f.*E_m)./(E_f.*d.*sqrt(3))).*x)+((sigma_f.*E_m.*(1-v_f))./E_f));
else
y2=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x)+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
end
end
semilogx(x,y1,x,y2);
grid on

Thanks in advance!
P.S.:
The function is as follows if you're having trouble reading it from the code

where "l" is "x".
3 commentaires
Mathieu NOE
le 13 Juil 2021
hello
are you sure that x, y1 and y2 exist ? and are not NaN ?
what do you get in your workspace when you type whos ?
João Novais
le 13 Juil 2021
Mathieu NOE
le 13 Juil 2021
there is something wrong probably in this for loop
for x=logspace(-6,2)
if x < l_c
y1=((eta_l.*eta_0.*((v_f.*sigma_f.*E_m)./(E_f.*d.*sqrt(3))).*x)+((sigma_f.*E_m.*(1-v_f))./E_f));
else
y2=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x)+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
end
end
at the end , x, y1 and y2 are scalars (see dimensions displayed in your workspace) and not vectors (should be same size as y ? )
the for loop must be rewritten with indexes for x and y1 , y2 - not the way you do it
suggestion (I cannot test it without your data and I am not sure that initializing y1 and y2 with zeros is appropriate - you should double check that) :
N = 100;
x =logspace(-6,2,N) ;
y1 = zeros(1,N);
y2 = zeros(1,N);
for ci = 1:N
if x(ci) < l_c
y1(ci)=((eta_l.*eta_0.*((v_f.*sigma_f.*E_m)./(E_f.*d.*sqrt(3))).*x(ci))+((sigma_f.*E_m.*(1-v_f))./E_f));
else
y2(ci)=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x(ci))+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


