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

2 vues (au cours des 30 derniers jours)
Michal Ulikowski
Michal Ulikowski le 19 Nov 2020
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

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 19 Nov 2020
Modifié(e) : KALYAN ACHARJYA le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by