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

2 次查看(过去 30 天)
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

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-11-19
编辑:KALYAN ACHARJYA 2020-11-19
"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.

更多回答(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