How do I get a for loop to move through values in an array?

2 views (last 30 days)
I'm trying to make a function that compares the standard deviation to a value to see if its below 1std of the mean. To do this I created some loops that should go through each value in an array and compare it with the same positioned value in the std array, and mark it as true or false. Here is the code:
function [within1std] = StdComparison(Parameters, Mean)
%Function will take the mean away from value, make it positive and compare
%to the standard deviation
% Detailed explanation goes here
StandardDeviation = movstd(Parameters, [5 4],1);
within1std = [];
for i = Parameters(:,i)
for j = Parameters(j,:)
Std1 = StandardDeviation(j,i);
DiffFromMean1 = Parameters(j,i) - Mean(j,i);
DiffFromMean1 = abs(DiffFromMean1);
if DiffFromMean1 <= Std1
within1std(j,i) = 'True';
else
within1std(j,i) = 'False';
end
end
end
end

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 19 Nov 2020
Edited: KALYAN ACHARJYA on 19 Nov 2020
"To do this I created some loops that should go through each value in an array and compare it with the same positioned value in the std array, and mark it as true or false. Here is the code"
Is such case you can avoid loop, using conditional statements-
result=array==std_array
The result will be another array of same size, with having elements 0 or 1. If 0, both same positioned values are not same, otherwise equal number.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!