"Brandon Rodriguez" <coasters2k@yahoo.com> wrote in message <gsfp69$19b$1@fred.mathworks.com>...
> Say I have a vector that's like this:
>
> [-6 -3 0 3 6]
>
> How can I get it get the number in between each of the two values to return something like:
>
> [-4.5 -1.5 1.5 4.5]
>
> Is there a built-in function that can do this? I'm asking because I'd like to avoid a loop if possible (but I'm thinking it's the only way). Thanks!
Here are a couple of ways to do it:
>> a = [-6 -3 0 3 6];
>> diff(a)/2 + a(1:end-1)
ans =
-4.5 -1.5 1.5 4.5
OR
>> (a(1:end-1) + a(2:end))/2
ans =
-4.5 -1.5 1.5 4.5
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
What are tags?
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.