MATLAB: Specifying a range in a double

doublefindMATLABmean

% Values is a 401x1 double: 1 - 401
% In this example, I want to take the mean from Values(90) to Values(110).
% Specify Bounds
MAX = 90; %
MIN = 110;
idy = find(Values == MIN);
idz = find(Values == MAX);
Values = mean(Values(idy:idz));
This is simple & should be returning 1 number from Values after taking the mean, but it's resulting in a 1×7^6 double.
Is there a syntax error that I'm overlooking here?

Best Answer

  • I think, that you want to do this:
    MAX = 110;
    MIN = 90;
    id = find( (MIN <= Values) & (Values <= MAX) )
    Values = mean(Values(id))
    I switched the MIN/MAX values