using relational operators on array and element

12 visualizaciones (últimos 30 días)
David Weise
David Weise el 7 de Oct. de 2019
Editada: Stephen23 el 9 de Oct. de 2019
Hy,
I'm trying to figure out a way to sort my experiment data. I have a list with values which I want to look at but first I need to delte the ones that don't fit my criteria. For this case I developed the following code:
%tolerance
x=1
%values
T1=5:-5:-15;
%values2
T2=30:5:55;
%values3
f=30:5:120;
%dimension
d=size(meassure);
d=d(1);
%applying tolerance to values I want to extract
var1=T1-x;
var2=T1+x;
%loop to check for criteria
for i=1:d
if T(i,6)>=var1 & T(i,6)<=var2;
else T(i,6)=NaN;
My problem now is, because var1 and var2 are arrays it puts NaN to every value. Even though one of the values fits the if.... criteria.
I hope someone can help me and I explained my problem well enough
  3 comentarios
David Weise
David Weise el 9 de Oct. de 2019
I know the basics of C and just learned some stuff about Matlab but not Python.
Stephen23
Stephen23 el 9 de Oct. de 2019
Editada: Stephen23 el 9 de Oct. de 2019
MATLAB is not very much like C.
The best way to learn basic MATLAB concepts is by working through the introdutory tutorials:

Iniciar sesión para comentar.

Respuesta aceptada

Daniel M
Daniel M el 7 de Oct. de 2019
if y>=var1 & y<=var2;
var1 = 4 -1 -6 -11 -16
var2 = 6 1 -4 -9 -14
Let's say y = 5, so the condition above will evaluate to
ans =
1×5 logical array
1 0 0 0 0
How do you want the if statement to handle a logical array?
Perhaps you want to look into one of the following functions
all()
any()
  2 comentarios
David Weise
David Weise el 9 de Oct. de 2019
Thanks for your answer. I tried this now but not getting the right answers.
for i=1:d
y=T(i,6)
if y>=var1 & y<=var2
if any(y==1)
else T(i,6)=NaN
end
end
end
The code is running but doesn't change anything
Daniel M
Daniel M el 9 de Oct. de 2019
I'm not sure you understand how if statements work. You should read up on that.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB 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