Plot range with semilogx

조회 수: 2 (최근 30일)
Jareth Rivas-Diaz
Jareth Rivas-Diaz 2019년 11월 9일
댓글: Jareth Rivas-Diaz 2019년 11월 9일
I am trying to use an array in my function, and then plot that same array as the x-axis. Even if I change "EfEm" to a single number (i.e. 400), it will not plot line. I believe my problem is wil "eta", but I am unsure on how to correct it so it will compute the range of EfEm. The correct output should be a line that starts flat, curves up from 10 to 200, and begins to plateau at around 400 until 1000.
% Constants and equations
EfEm = 0:1000;
xi = 2;
eta = (EfEm - 1)/(EfEm + xi);
y70 = (1 + xi * eta * .7)/(1 - eta * .7);
% Plot
figure
semilogx(EfEm,y70, 'r');
ylim ([0,20]);
yticks([0,4,8,12,16,20]);
legend('V_f = 70%');
xlabel("E_f/E_m");
ylabel("E_2/E_m")
grid on

채택된 답변

the cyclist
the cyclist 2019년 11월 9일
편집: the cyclist 2019년 11월 9일
You needed element-wise instead of matrix division in these two lines:
eta = (EfEm - 1)./(EfEm + xi);
y70 = (1 + xi * eta * .7)./(1 - eta * .7);
Note where I used ./ instead of just / in the code. See the documentation on array vs. matrix operations.
test.png
  댓글 수: 1
Jareth Rivas-Diaz
Jareth Rivas-Diaz 2019년 11월 9일
That worked! I feel so dumb. Thanks for the help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Log Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by