I have an array of angles and I need to identify periods where this array is above or below certain thresholds

Array of angles ranges from 0 - 360. I need to know the indices of values below 15, between 165 and 195, and above 345. Attempted using:
array_logical = array < 15 && 165 < array < 195 && 345 < array;
array_logical = array < 15 || 165 < array < 195 || 345 < array;
What is the best way to apply these three conditions in one logical array?

 채택된 답변

ix= (x<15 | iswithin(x,166,194) | x>345;
where used the "syntactic sugar" of help function for the compound condition to make the upper level expression simpler to read. NB: since my function is inclusive changed the limits to match
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
Your problem above is primarily using the short-circuiting operators instead of the element-wise ones (the "double operator" form instead of single).
"These operations are explained in the MATLAB Programming documentation on logical operators, under the topic of Basic Program Components."

댓글 수: 2

A variation of this worked, so thanks!
Good to hear...I see I left an extraneous '(' around--was going to wrap terms but decided it didn't need it and didn't clean 'em all up...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mischa Kim
Mischa Kim 2014년 4월 10일
편집: Mischa Kim 2014년 4월 10일
Use
array_ind = find(array<15 | (array>=165 & array<=195) | array>345)

댓글 수: 2

This found the indices, but I needed the logical array to properly identify where these sections are in addition to the times inbetween. Thanks for the help though!
Identical to my w/o the sugar-coating--just drop find

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

질문:

2014년 4월 10일

댓글:

dpb
2014년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by