76 views (last 30 days)

Hi all

I am doing some work with suspension dampers and trying to model them. To do this i have put a damper on a suspension dynamometer to measure the displacement, velocity and force against time.

When plotting Velocity against force you end up with a hysteresis loop, which i need to find the average values for each velocity. What i mean by this is that for every x value, there are multiple corresponding y values. I need to find the average of those multiple y values, to give me a single line (or two lines if you prefer, one for the positive y values, one for the negative.

For example,

x = 0.582 & y = [2 7 5 13 4] average of y at x = 0.582 is 6.2.

I have also attached pictures to visually illustrate what i am trying to achieve.

Many Thanks Ross

KL
on 27 Feb 2018

Edited: KL
on 27 Feb 2018

A lot depend on how you have stored your data. I can think of something with table. You could either sort your data into a table or work with tables right from the beginning.

x = 0.582;

y = [2 7 5 13 4];

%now create table

T = table(x, [y, -y],'v',{'x','y'})

%add new columns calculating mean

T.y_mean_p = mean(T.y(T.x==0.582&T.y>=0));

T.y_mean_n = mean(T.y(T.x==0.582&T.y<=0))

T =

x y y_mean_p y_mean_n

_____ _____________ ________ ________

0.582 [1x10 double] 6.2 -6.2

keep in mind, comparing x==some_floating_point_value could be problematic. Do it within some tolerance.

Sign in to comment.

Daniel Bridges
on 27 Feb 2018

Edited: Daniel Bridges
on 27 Feb 2018

Sounds to me that what you want to do is have vectors of data x and y, same length.

Then -- sorry, talking off the top of my head so specific commands or syntax may be wrong, but to give you an idea -- something like

indices = find(x==givenvalue);

to index only those portions of y that correspond to your given value for x,

result = mean(y(indices))

Of course you'll need to repeat x values in the x vector for each of the multiple y(x) values.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/385121-finding-average-value-of-multiple-y-values-for-a-single-x-value#comment_540000

⋮## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/385121-finding-average-value-of-multiple-y-values-for-a-single-x-value#comment_540000

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/385121-finding-average-value-of-multiple-y-values-for-a-single-x-value#comment_540005

⋮## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/385121-finding-average-value-of-multiple-y-values-for-a-single-x-value#comment_540005

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/385121-finding-average-value-of-multiple-y-values-for-a-single-x-value#comment_540209

⋮## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/385121-finding-average-value-of-multiple-y-values-for-a-single-x-value#comment_540209

Sign in to comment.