Parse Error at '>' Issue
이전 댓글 표시
I have to select (and count) particular numbers from a series. The selection should have numbers less than 900 but more than 700. I was getting a parse error at '>' with below code. There is only 1 column.
a=data(data(:,1) <900 && >700);
n=numel(a)
Please let me know how can I get through this.
답변 (4개)
Steven Lord
2017년 3월 23일
0 개 추천
You need to explicitly write what needs to be greater than 700 for the condition to be satisfied. MATLAB does not assume that you meant "data(:, 1) > 700" in that indexing expression.
댓글 수: 2
Aniket Doke
2017년 3월 24일
Roger Stafford
2017년 3월 24일
편집: Roger Stafford
2017년 3월 24일
@Aniket Doke. I think you still don’t understand. You can’t write:
A<900 & >700
That is incorrect syntax in matlab. You must write:
A<900 & A>700
dpb
2017년 3월 23일
I use a utility "syntactic sugar" for such purposes...
a=isinside(a,700,900);
where
function flg=isinside(x,lo,hi)
% returns T for values within range of inputs
% SYNTAX:
% [log] = isinside(x,lo,hi)
% returns T for x between lo and hi values, exclusive
flg= (x>lo) & (x<hi);
Roger Stafford
2017년 3월 23일
0 개 추천
Also you cannot use the short-circuit && on vectors, only on scalars.
카테고리
도움말 센터 및 File Exchange에서 Time Series Collections에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!