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

Mathieu NOE
Mathieu NOE 2021년 7월 13일
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 ?
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
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

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2021년 7월 13일

0 개 추천

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

Thank you for your answer!
i wrote that code down like this but it told me that the vectors need to be the same length.
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));
plot(x,y1,x,y2)
And then on the command window
Error using plot
Vectors must be the same length.
Error in kellytysonsimu (line 13)
plot(x,y1,x,y2)
The ‘x’ vectors need to change as well:
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));
plot(x(idx),y1,x(~idx),y2)
That should work.
.
João Novais
João Novais 2021년 7월 14일
Thank you so much!!
Star Strider
Star Strider 2021년 7월 14일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2021년 7월 13일

댓글:

2021년 7월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by