How do I average a data which runs on a cycle?

I have a data file that goes like -1 0.2 -0.5 0.15 0 0.143 0.5 0.122 1 0.1234 1 0.233 0.5 0.32 0 0.322 -0.5 1.22 -1 1.333 then cycle 2 which has same x values but different y values . the cylce continues for 100 times. i want to have a average of y values for each x values.so finally i have the average y value

 採用された回答

John D'Errico
John D'Errico 2014 年 11 月 24 日

0 投票

You could use my consolidator , found on the file exchange.
It can form the mean y value for each independent x. It could even be used to compute a standard deviation of y within each x.

3 件のコメント

DebiPrasad
DebiPrasad 2014 年 11 月 24 日
Thats a really great function. and it works but I need the data to be cylcic . -1 to 1 and then 1 to -1. the function averages all the duplicities and gives me -1 to 1.
DebiPrasad
DebiPrasad 2014 年 11 月 24 日
I should get data from -2 to 2 and then again from 2 to -2. so it gives me a cycle!
John D'Errico
John D'Errico 2014 年 11 月 25 日
Then you need to tell consolidator that there are two types of points. Thus you have an increasing section and a decreasing one. Flag each point with a 1 or -1 that indicates which way the cycle is going. Then use consolidator with the 2 dimensional input to distinguish which elements to average.

サインインしてコメントする。

その他の回答 (1 件)

Thorsten
Thorsten 2014 年 11 月 24 日
編集済み: Thorsten 2014 年 11 月 24 日

1 投票

Read your data into one big 100xN matrix D (e.g., using dlmread) and then use mean(D). Voila.

4 件のコメント

DebiPrasad
DebiPrasad 2014 年 11 月 24 日
Thanks Thorsten. But I dont want the mean of all y values. But y values of each x values. Since its a cycle, i will get 100 x values of values from -1,5 to 1.5, and corresponding y values. the y data should be the y mean of the each y value in the x value.
Thorsten
Thorsten 2014 年 11 月 24 日
編集済み: Thorsten 2014 年 11 月 24 日
Oh, I see. Is your example one actual line of your file? It does not contain x values -1.5 and 1.5. Are the x values always in the same order -1, -0.5, 0.5, 1, 1, 0.5, -0.5, -1? Then you can construct your Y matrix from the big data matrix D as
Y = [D(:, 2:2:10); D(:, 20:-2:12)];
and compute the mean as
mean(Y)
for values of a = -1:0.5:1;
If you need something else, please provide more information about the file; maybe you should post the file or the first, say, 10 lines.
DebiPrasad
DebiPrasad 2014 年 11 月 24 日
I should get data from -2 to 2 and then again from 2 to -2. so it gives me a cycle!
Thorsten
Thorsten 2014 年 11 月 26 日
But in your example you have only x values that run from -1 to 1 and back from 1 to -1. So what do the real data look like? Could you provide the file?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

タグ

質問済み:

2014 年 11 月 24 日

コメント済み:

2014 年 11 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by