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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 19 Nov. 2020
Bearbeitet: KALYAN ACHARJYA am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by