23 views (last 30 days)

Hello everyone,

I want to calculate mean values of specific (but dynamic) intervals across several result files. I know how I get more than one results file into MATLAB and the other basics.

But what I dont know is the following: an interval should be defined/ starting when a value is between -0.05 and 0.05 in a specific column. It is dynamic, because it sometimes lasts for 8 seconds, sometimes for 10 seconds. So the interval should be ended when the value is <-0.05 or >0.05.

Then i want to calculate the mean value of data from another column according to the defined intervals in the other column.

I hope u understand what I want to do.

Thanks in advance

Jos (10584)
on 1 Aug 2019

% interval and value are the relevant columns of your data matrix

interval = data(:,3)

value = data(:,2)

% find the sections

q = ~(interval < -.05 | interval > .05)

dq = diff([false q false])

ix1 = find(dq==1)

ix2 = find(dq == -1) - 1

% function to apply to each section

myfun = @(k) mean(value(ix1(k):ix2(k)))

R = arrayfun(myfun, 1:numel(ix1)) % mean of each section

not tested but it should work :-)

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730720

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730720

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730725

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730725

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730744

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730744

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730793

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730793

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730795

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730795

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730798

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730798

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730824

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474441-calculate-mean-values-of-specific-but-dynamic-intervals#comment_730824

Sign in to comment.