Plotting a Semi-Log Plot as a Function of Time
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I am fairly new to Matlab plotting and I can't figure out the semi-log plotting.
I would like to plot the following as a semi-log plot:
Y-axis
- Y = 50 for t < 0.05
- Y = 31.38 + 0.931/t for 0.05 ≤ t ≥ 7.758
- The Y-axis will have intervals of 0, 10, 20, 30, 40, 50, 60.
X-axis (time axis)
- The X-axis (semi-log) would range from [0.01, 0.1, 1, 10, 100). < -- logspace (-2,2)
- A marker for 7 to be included on the x-axis.
Any help would be appreciated. Thank you.
채택된 답변
Cris LaPierre
2024년 12월 15일
I'd do something like this. Let me know if you have any questions
t = logspace(-2,2);
% one way to implement a piecewise function in MATLAB
y = (50*(t<0.05) + (31.38 + 0.931./t).*(t>=0.05));
% Creat the plot
semilogx(t,y)
ylim([0,60]) % set range of visible y values. Otherwise, plot collapses to range plotted
yticks(0:10:60) % set desired ytick locations
% by default, log tick lablels are exponenents (e.g 10^-2). This displays
% the equivalent numeric representation
xticklabels(string([0.01, 0.1, 1, 10, 100]))
xline(7,'-','t=7') % add a lins at x=7. Could also use this: plot(7,0,'rx')
xlabel('Time')

댓글 수: 7
Cris,
Thank you very much. This will certainly help me.
Two questions:
1) In the third line, why is there a period following 0.93t and a period before the *?
2) I modifed iine 3 as follows: y = (50*(t<0.05) + (31.38 + 0.931./t).*(7.758>=t>=0.05)+(31.5).*(t>7.758)); But for some reason my plot starts at 60 instead of 50 at time 0.01 and I don't know why. All I did was just add an extra time interval for beyond t = 7.758.
3) Is there a way to make the text '7' appear along the time axis? From the examples I have seen I don't think so. I am using R2017a so when using 'xline', I get the followng error: ---> 'Undefined function or variable 'xline'. Using plot (7,0,'x'), returned a completely different looking plot. No problem, I can add it manually
Thanks, Gus
Walter Roberson
2024년 12월 16일
편집: Walter Roberson
2024년 12월 16일
1) Yes
2) The 0.931./t period is there because it is specifying that the operator named ./ is being used rather than the operator named / . The operator named / is formally known as mrdivide, / Matrix Right Divide, and A/B is approximately the same as A * inv(B) where * is the algebraic matrix multiplication operator. The operator named ./ is formally known as rdivide, ./ Right Divide and A./B is element-wide division, A(I,J) divided by B(I,J) . 0.931./t means [0.931 divided by t(1), 0.931 divided by t(2), 0.931 divided by t(3)] and so on instead of a pseudo-inverse calculation.
3) xticks(sort([xticks(), 7]))
Thanks Walter.
Question:
I modifed iine 3 as follows: y = (50*(t<0.05) + (31.38 + 0.931./t).*(7.758>=t>=0.05)+(31.5*(t>7.758))); But for some reason my plot starts shows a vertical line at t-0.05 instead of 50 and then the plot begins, I have no idea why.
All I did was just add an extra time interval such that y = 31.5 for beyond t = 7.758.
Regards,
Gus
The (31.38 + 0.931./t).*(7.758>=t>=0.05) part of the expression will be parsed as
(31.38 + 0.931./t).*((7.758>=t)>=0.05)
The result of 7.758>=t is either 0 (false) or 1 (true). That 0 or 1 will then be compared to 0.05 which is unlikely to be what you want.
MATLAB does not normally support chaining comparison operators. (There is undocumented support for chaining comparison operators for symbolic expressions in the "cond" positions in piecewise() )
So to correct this, I need to look in to the 'cond' command?
This what i want to achieve.

y = (50)*(t<0.05) + (31.38 + 0.931./t).*(7.758>=t & t>=0.05) + (31.5)*(t>7.758)
Gus
2024년 12월 16일
Thank you very much Walter. Very much appreciated.
So the logical 'AND' was needed in this case. Makes sense now.
Regards,
Gus
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
