Filter löschen
Filter löschen

While/for loop to write a set of values only when they are in a certain range.

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Jacob Halbrooks
Jacob Halbrooks am 12 Mär. 2012
I would suggest a combination of ALL with logical indexing and masking:
dataToWrite = XY(all((XY >= 400) & (XY <= 500), 2),:);

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by