MATLAB: How to calculate a portion of the data’s average

meansort data

I have an array of about 7000 data points. The data ranges from 30 to 100 in increments of 10. The data was collected using strain gauges, so the numbers have some fluctuation. I want to calculate the average for each of the set point values. I need the code to be flexible to fit other tests, so I will not necessarily know how many data points are in each section. I have attached the excel file containing the sample data. In the beginning of my code, I read the data in using the xlsread('file') function and store it as an array.

Best Answer

" I will not necessarily know how many data points are in each section" Lets take a random sets in which you want to take average. Just put your sets in cells and use cellfun. For example, I have taken random sets 'index'
A=xlsread('sample data.xlsx');
index={[1:2536],[2536:4589],[4589:6958],[6958:7593]}
setmean=cellfun(@(x) nanmean(A(x)),index)
Related Question