Matlab isn't ploting the function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
João Novais
el 13 de Jul. de 2021
Comentada: Star Strider
el 14 de Jul. de 2021
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 comentarios
Mathieu NOE
el 13 de Jul. de 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
Respuesta aceptada
Star Strider
el 13 de Jul. de 2021
I do not have any of the data, however I believe that I understand the problem:
for x=logspace(-6,2)
y = x.^2;
end
figure
plot(x, y, '.-')
However this produces a different result:
x=logspace(-6,2)
y = x.^2;
figure
plot(x, y, '.-')
% return
Try something like this —
x=logspace(-6,2)
idx = x < l_c
y1=((eta_l.*eta_0.*((v_f.*sigma_f.*E_m)./(E_f.*d.*sqrt(3))).*x(idx))+((sigma_f.*E_m.*(1-v_f))./E_f));
y2=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x(~idx))+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
Be sure that all the ‘x’ references are ‘x(idx)’ or ‘x(~idx)’. I only found one in each assignment, and changed those.
.
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Sparse Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!