Writing a loop to check the numbers in an array do not exceed a constant value
5 views (last 30 days)
Show older comments
Hi, I am writing this program and need to write a for loop or similar in order to find if the values inside two arrays do not exceed a certain value
my two array/vectors are as follows. case_one,two.... are just numbers as same as W_1,2,3....
CG = [Case_one;Case_two;Case_three;Case_four;Case_five;Case_six;Case_seven;Case_eight;Case_nine;Case_ten];
W_array = [W_1;W_2;W_3;W_4;W_5;W_6;W_7;W_8;W_9;W_10];
I want to make sure these values inside do not exceed 2300 for W_array. values are within 35 - 47 for CG array. If they do exceed or not withing the range, I need to out put the text "warning". please help me with this. I am new to mathlab.
0 Comments
Accepted Answer
Geoff Hayes
on 14 Feb 2015
Zcarfaz - use find to determine if you have any elements that fall outside of your range. For example, if
W_array = [4 2301 178 2300 1299];
then
if ~isempty(find(W_array>2300,1))
fprintf('W_array has at least one element that exceeds 2300\n');
end
will print a warning to the console indicating that there is at least one element in your array that exceeds 2300. A similar approach can be used for the interval 35-47 (use the and operator with two conditions).
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!