While/for loop to write a set of values only when they are in a certain range.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So, I have a variable called XY. An whos on that variable looks like this:
Name Size Bytes Class Attributes
XY 2897x2 46352 double
A snippet of that variable looks like is this:
A B
527 393
523 397
513 409
506 411
509 412
What I need is a while/for loop that will write the values of XY to a new variable (lets call it XY2) only when both A and B column is in certain value range. For instance, in the example above I only want to write A and B to excel, when both A and B are within 400-500. So I only want to write the last 3 sets, and not the 2 on the top. What is the easies way to go about this?
0 comentarios
Respuesta aceptada
Jacob Halbrooks
el 12 de Mzo. de 2012
I would suggest a combination of ALL with logical indexing and masking:
dataToWrite = XY(all((XY >= 400) & (XY <= 500), 2),:);
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!