Matlab isn't ploting the function

2 visualizaciones (últimos 30 días)
João Novais
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
João Novais
João Novais el 13 de Jul. de 2021
Yes they do exist. For instance this is the graph of the whole function y2 by it's own
The thing is that i'm having trouble ploting them together. When i type "whos" it appears that all my variables appear as "double"
Name Size Bytes Class Attributes
E_f 1x1 8 double
E_m 1x1 8 double
d 1x1 8 double
eta_0 1x1 8 double
eta_l 1x1 8 double
l_c 1x1 8 double
sigma_f 1x1 8 double
v_f 1x1 8 double
x 1x1 8 double
y 1x100 800 double
y1 1x1 8 double
y2 1x1 8 double
Mathieu NOE
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

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
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)
x = 1×50
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0002 0.0003 0.0004 0.0006 0.0009 0.0013 0.0018 0.0027 0.0039 0.0057 0.0083 0.0121 0.0176 0.0256 0.0373 0.0543
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
João Novais
João Novais el 14 de Jul. de 2021
Thank you so much!!
Star Strider
Star Strider el 14 de Jul. de 2021
As always, my pleasure!
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by