Parse Error at '>' Issue

7 visualizaciones (últimos 30 días)
Aniket Doke
Aniket Doke el 23 de Mzo. de 2017
Editada: Roger Stafford el 24 de Mzo. de 2017
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.

Respuestas (4)

Steven Lord
Steven Lord el 23 de Mzo. de 2017
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 comentarios
Aniket Doke
Aniket Doke el 24 de Mzo. de 2017
The condition for <900 gives me correct answer. When I add one more constraint (>700), it gives me an error.
Roger Stafford
Roger Stafford el 24 de Mzo. de 2017
Editada: Roger Stafford el 24 de Mzo. de 2017
@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

Iniciar sesión para comentar.


dpb
dpb el 23 de Mzo. de 2017
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);
  1 comentario
Aniket Doke
Aniket Doke el 24 de Mzo. de 2017
Okay. I will give it a try! Thanks!

Iniciar sesión para comentar.


Roger Stafford
Roger Stafford el 23 de Mzo. de 2017
Also you cannot use the short-circuit && on vectors, only on scalars.
  1 comentario
Aniket Doke
Aniket Doke el 24 de Mzo. de 2017
Understood. Thanks!

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 24 de Mzo. de 2017
a = data(data(:,1) <900 & data(:,1) >700);
  1 comentario
Aniket Doke
Aniket Doke el 24 de Mzo. de 2017
Great. I got the correct answer with this! Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Time Series Collections en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by