Plotting a Semi-Log Plot as a Function of Time
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
