How to add trendline to semilog plot in matlab

  • Context: MATLAB 
  • Thread starter Thread starter adeeyo
  • Start date Start date
  • Tags Tags
    Matlab Plot
Click For Summary
SUMMARY

This discussion provides a clear method for creating a semilogarithmic plot in MATLAB using the vectors x and y. The specific commands include using semilogx to plot the data points and setting labels and titles accordingly. To add a trendline, users are advised to search for "MATLAB trendline" for straightforward implementation. The example provided illustrates the use of MATLAB for visualizing data effectively.

PREREQUISITES
  • Familiarity with MATLAB syntax and environment
  • Understanding of semilogarithmic plotting techniques
  • Basic knowledge of data visualization principles
  • Ability to manipulate vectors in MATLAB
NEXT STEPS
  • Research how to implement trendlines in MATLAB using polyfit and polyval
  • Explore advanced plotting options in MATLAB, such as customizing plot aesthetics
  • Learn about logarithmic scales and their applications in data analysis
  • Investigate MATLAB's built-in functions for statistical analysis of plotted data
USEFUL FOR

This discussion is beneficial for data analysts, engineers, and researchers who utilize MATLAB for data visualization and require guidance on creating semilogarithmic plots with trendlines.

adeeyo
Messages
20
Reaction score
0
Hi,
I have x and y vectors, x=[ 90868 68151 45434 34076 27261 13631 6816 3408 2273 1948 1705 1137 853 683 569 455 342 274 228 190]; y=[ 3680 3723 3800 3866 3920 4103 4250 4320 4340 4344 4350 4364 4373 4379 4384 4393 4398 4402 4405 4407];
I need to plot semilogx in MATLAB and add trendline and get the slope as shown in the image attached and also shown in this link http://img708.imageshack.us/img708/7717/0056005c.jpg
Please how do I go about it?

Thanks

adeeyo
 

Attachments

  • 00560_05c.jpg
    00560_05c.jpg
    26.7 KB · Views: 1,173
Last edited by a moderator:
Physics news on Phys.org
Hey adeeyo.

In MATLAB, you should type or enter the following to produce the semilogx plot:

x = [ 90868 68151 45434 34076 27261 13631 6816 3408 2273 1948 1705 1137 853 683 569 455 342 274 228 190];
y=[ 3680 3723 3800 3866 3920 4103 4250 4320 4340 4344 4350 4364 4373 4379 4384 4393 4398 4402 4405 4407];

h = semilogx(x,y,'*','color','black')
xlabel('Horner Time Function - Tp=13630.0');
ylabel('Pressure (psia)');
title('Ex. 5-1: Semilog (Horner) Plot');

I have to run for now but the trendline should be straightforward if you just google "matlab trendline"

Cheers