How to process multiple matrices. Checking whether the elements of a matrix are within the specified range
Show older comments
Hello. I have 55 matrices 288x1 named Load1, Load2, Load3, ..., Load55. I need to create a for loop which checks whether the values are between 207 and 253. If one of the values exceeds 253 or is less than 207, I need to display the name of this variable. For example, one of the elements of matrix Load7 is 205. In this case, the program should display 'Load7'. Ultimately, I need to get a list of variables which values are not within specified range. Also, the script has to calculate the total number of variables which values are not within the range.
The output of the script shall look like, for example:
The Loads which are not within the range: Load7, Load25, Load37. The total number of loads: 3
Any help is greatly appreciated. Thank you.
3 Comments
dpb
on 24 Feb 2017
"55 matrices 288x1 named Load1, Load2, Load3, ..., Load55" which is the basis of your problem. Do NOT do this; load the data into a 2D array and the problem is trivial.
John BG
on 25 Feb 2017
may be Yesbol is new in MATLAB and doesn't know how to LOAD THE DATA INTO 2D ARRAY
may be Yesbol knows a way, but would like the experts to show whether there's a better way.
as trivial as it is, would you please supply a valid answer? if you don't I will
regards
Do NOT create lots of variables named Load1, Load2, load3, etc. This will make your code slow and buggy. Read this to know why, and what the much better alternatives are (hint: indexing):
Accepted Answer
More Answers (1)
John D'Errico
on 24 Feb 2017
1 vote
And this is only one of the reasons why what you did is a terribly bad idea. Combine all into one matrix. Do it once. Get it over with. And next time, learn not to create multiple numbered arrays.
Instead, learn to create matrices. With a matrix, your question becomes one simple line of code to test them all at once.
Categories
Find more on Loops and Conditional Statements 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!