How to find if a cell reaches an average value in a specific amount of instances.

조회 수: 1 (최근 30일)
I have a cell array thats made up of different vectors. What I want to do is eveluate each vector in the cell to determine if at any point in the vector a mean of a say 10 entries falls within +or - 10 of a value?
  댓글 수: 2
C B
C B 2021년 10월 6일
can you Please eloobrate what ipnut and your expected output?
like this
input should be
A= {[11 23 44 99] [111 223 434 939] [1111 2223 433 9339]}
Jan
Jan 2021년 10월 6일
I do not undestand this part: "determine if at any point in the vector a mean of a say 10 entries falls within +or - 10 of a value".

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 10월 6일
Try this:
A= {[11 23 44 99] [111 223 434 939] [1111 2223 433 9339]}
targetValue = 426; % Whatever.
for k = 1 : length(A)
thisVector = A{k};
fprintf('\nVector #%d is', k); disp(thisVector);
thisMean = mean(thisVector);
fprintf(' The mean for vector #%d is %f.\n', k, thisMean);
difference = abs(thisMean - targetValue);
percentDifference = 100 * difference / targetValue;
fprintf(' The difference of the mean from the target value of %.1f is %.2f = %.2f%%.\n', targetValue, difference, percentDifference);
if percentDifference < 10
% It's within 10% of the target value.
fprintf('Yay!!!! Cell #%d has a mean value that is within 10 percent of %.2f.\n', k, targetValue)
end
end
You'll see
Vector #1 is 11 23 44 99
The mean for vector #1 is 44.250000.
The difference of the mean from the target value of 426.0 is 381.75 = 89.61%.
Vector #2 is 111 223 434 939
The mean for vector #2 is 426.750000.
The difference of the mean from the target value of 426.0 is 0.75 = 0.18%.
Yay!!!! Cell #2 has a mean value that is within 10 percent of 426.00.
Vector #3 is 1111 2223 433 9339
The mean for vector #3 is 3276.500000.
The difference of the mean from the target value of 426.0 is 2850.50 = 669.13%.
Obviously the code could be shortened a lot by taking out the informative messages.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by