How to do the example below in MatLab? I am dealing with same sort of problem in matlab
Show older comments
Problem:
i have 3 csv files named file1, file2, file3. Each CSV is filled with 3 Columns and 5653 rows:
1 0 -95
2 0 -94
3 0 -93
...
51 0 -93
0 1 -92
1 1 -91
2 1 -90
First column is a X variable 2nd is a y variable, 3rd is a measured value from which I want to have the mean.
What I want to do is:
- read first row of file 1
- read first row of file 2
- read first row of file 3 and then count the mean of the measured value.
So for example:
file1 row1 -98
file2 row1 -97
file3 row1 -95
mean 96,666666667
i want to write that mean into a new csv file with the following format
1,0,mean_of_row1 (which would be 96,666666667)
2,0,mean_of_row2
3,0,mean_of_row3
4,0,mean_of_row4
Solution in Python:
import pandas as pd
df1=pd.read_csv('file1.txt',names=['x1','Y1','Value1'],nrows=5356)
df2=pd.read_csv('file2.txt',names=['x2','Y2','Value2'],nrows=5356)
df3=pd.read_csv('text3.txt',names=['x3','Y3','Value3'],nrows=5356)
df_concat= pd.concat([df1,df2,df3], axis=1)
print df_concat
df_concat['meanvalue']=df_concat[['Value1','Value2','Value3']].mean(axis=1)
print(df_concat.to_csv(columns=['meanvalue'],index=False))
Accepted Answer
More Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!