필터 지우기
필터 지우기

select data from a text file

조회 수: 1 (최근 30일)
UWM
UWM 2016년 3월 16일
댓글: UWM 2016년 3월 16일
Matlab users,
I have a question regarding selecting certain data from a text file. First of all I need to find all rows where the values in first and second columns are the same (measurement epoch). Then I have to calculate the arithmetic mean of the values in fourth, fifth and sixth columns (for the identified “the same” rows). Finally I want to save in the output file “age of observation: values from first and second column" and corresponding to them arithmetic mean. Below there is attached a small piece of the input file.
Does anyone have any suggestions on how I might be able to do this?
Many thanks!
0 50 1 -0.20 0.92 -1.95
0 55 1 -0.20 0.94 -1.97
1 0 1 -0.21 0.95 -2.00
1 5 1 -0.33 0.66 -1.86
1 10 1 -0.33 0.68 -1.88
1 15 1 -0.38 0.66 -1.98
1 20 1 -0.38 0.67 -2.00
1 25 1 -0.44 0.65 -2.13
1 30 1 -0.44 0.25 -1.51
1 35 1 -0.44 0.26 -1.52
1 40 1 -0.48 0.30 -1.69
1 45 1 -0.48 0.30 -1.70
1 50 1 -0.51 0.31 -1.79
1 55 1 -0.51 0.31 -1.79
2 0 1 -0.57 0.32 -1.96
2 5 1 -0.57 0.32 -1.95
2 10 1 -0.62 0.30 -2.04
2 15 1 -0.62 0.29 -2.03
1 50 2 -0.22 1.33 -2.61
1 55 2 -0.22 1.34 -2.64
2 0 2 -0.35 1.23 -2.81
2 5 2 -0.28 1.15 -2.50
2 10 2 -0.28 1.16 -2.52
2 15 2 -0.23 1.11 -2.29
2 20 2 -0.28 0.74 -1.85
2 25 2 -0.28 0.75 -1.86
2 30 2 -0.28 0.71 -1.81
2 35 2 -0.28 0.72 -1.82
2 40 2 -0.29 0.70 -1.83
2 45 2 -0.29 0.71 -1.83
2 50 2 -0.33 0.69 -1.91

채택된 답변

Guillaume
Guillaume 2016년 3월 16일
Reading the file is easy with dlmread or readtable.
For calculating the means of identical epoch, you can use the Split-Apply-Combine workflow introduced in R2015b, or unique with accumarray:
[epoch, ~, subs] = unique(m(:, [1 2]), 'rows'); %find unique epochs as rows of column 1 and 2
meancol5 = accumarray(subs, m(:, 5), [], @mean); %mean of column 5 by epoch
  댓글 수: 1
UWM
UWM 2016년 3월 16일
Thank you for help. It works perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by