![]() ![]() That way, I did not need to discard all data at low temperatures. So I looked for data where the temperature was sufficiently low AND the speed was very low (which could potentially mean the sensor was frozen). But I didn't want to delete ALL the values below freezing. The problem is that when the temperature gets near or below freezing, the speed sensor might freeze. ![]() I had 2 arrays, hourly temperature and speed. I recently used this in the context of finding suspect data values. I could, of course, calculate a compound condition where only either one or the other condition needs to be true using logical or (via |). X(compoundCondInd)ĭid you see how easy it is to combine multiple conditions? I simply look for each of condition, getting back logical arrays, and then compute a logical array where the two input arrays are both true (via &). We can see we found suitable values at locations 3 and 19. compoundCondInd = (X < target) & iseven(X) We have the pieces of code we need already. This is very natural to do with logical indexing. ![]() Now I would like to find the values in X that are less than target and are even. iseven = ~logical(rem(x,2))įind Values Meeting More Than One Condition Let me create an anonymous function that returns true ( logical(1)) for values that are even integers. XtargetLogical = X(logInd)īoth methods return the results. I can now use this array to extract the desired values from X. whos logInd Name Size Bytes Class Attributes The array logInd is not an array of double numbers, but have the class logical. MATLAB returns an array that matches the elements of the array X, element-by-element holding 1s where the matching values in X are the desired values, and 0s otherwise. Xtarget = X(ind)Īnother way to accomplish the same outcome is to use the logical expression to directly perform the indexing operation. And we can use these to extract the values. You can see that find returns the indices into the array X that have values less than the target. Here's how I can do it using the function find. Suppose I have an array of integers, not sorted, and want to find the ones that are less than a certain number. Find Values Meeting More Than One Condition. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |