Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating using individual array entries

Status
Not open for further replies.

JohnKGH

Civil/Environmental
Jul 26, 2005
12
Hi,

Im a beginner at matlab so please bear with me. I want to create a function that has 2 inputs from a datafile. Both are individual columns of a three column data file with input 1 as column 1 and input 2 as column 2. Is there a way I can make a formula to find the differences between consecutive entries in column 1? For instance, column 1 is:
5
8
2
7, therefore the output would be 3,-6,5. Any ideas? Thanks for any help.
 
Replies continue below

Recommended for you

Wouldn't it be the same as what you would do mathematically, e.g., MD=M[i+1]-M? where i ranges from imin to imax-1

TTFN



 
JohnKGH,

Boy you really are new to Matlab! Operations on columns of data are the bread and butter of Matlab analyses:


>> x=[5 8 2 7]'

x =

5
8
2
7

>> diff(x)

ans =

3
-6
5
 
Wow...I feel stupid. Thanks for the tremendous help you guys!. BTW, is there a good website to reference for programming help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor