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

1 次查看(过去 30 天)
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?

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by