Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

i need help with finding the right number by calculating the average between 2 set of points at a time

1 view (last 30 days)
I've a project, and I'm new to matlab, never used it before this project. I'm trying to create a for loop with an if statment inside it. The for loop purpace is to find the average between 2 given points at a time form 8 values, and the "if" statement is to check if the the average is more than 1% greater than 119.2. If it is greater, then we need to use the average we just found, and find the average between the first point and the new point, until we find the correct answer, and then the loop can move on to the next set of points.
  1 Comment
dpb
dpb on 11 May 2020
In MATLAB, more than likely you don't need the loop, but it's not clear precisely what you're looking for...
Attach a small sample dataset and show us the result you want for it...it can be 10 or so points, number of points is immaterial as long as it demonstrates the problem.

Answers (1)

Image Analyst
Image Analyst on 11 May 2020
Put your signals into 8 rows of a matrix. Then to find the average of the 8 rows, you need to use mean
meanSignal = mean(allSignals, 1);
threshold = 1.01 * 119.2
for k = index1 : index2
% Find the mean value at index k;
meank = meanSignal(k);
if meank > threshold
% if it is greater then we need to use the average we just found
% and find the average between the first point and the new point
meanSignal(k) = mean(meanSignal(index1 : k)); % Replace with mean up until this index.
end
end

This question is closed.

Community Treasure Hunt

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

Start Hunting!