Plotting a Semi-Log Plot as a Function of Time

44 Ansichten (letzte 30 Tage)
Gus Giannakopoulos
Gus Giannakopoulos am 15 Dez. 2024 um 3:25
Kommentiert: Gus Giannakopoulos am 16 Dez. 2024 um 2:38
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.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 15 Dez. 2024 um 4:30
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 Kommentare
Walter Roberson
Walter Roberson am 16 Dez. 2024 um 2:34
y = (50)*(t<0.05) + (31.38 + 0.931./t).*(7.758>=t & t>=0.05) + (31.5)*(t>7.758)
Gus Giannakopoulos
Gus Giannakopoulos am 16 Dez. 2024 um 2:38
Thank you very much Walter. Very much appreciated.
So the logical 'AND' was needed in this case. Makes sense now.
Regards,
Gus

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by