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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 19 de Nov. de 2020
Editada: KALYAN ACHARJYA el 19 de Nov. de 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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by