フィルターのクリア

How to store a new variable based on a range from another column?

3 ビュー (過去 30 日間)
Andrew Lackey
Andrew Lackey 2021 年 9 月 2 日
コメント済み: Andrew Lackey 2021 年 9 月 2 日
I have a .txt file with 2 columns (X,Y).
I would like to create a variable that represents a range of Y, but have that range based on a range of X that I select.
For example:
X = [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10]
Y = [-10, -9, -8, -7, -6, 0, 6, 7, 8, 9, 10]
Now I want Variable Y_a to be a range of y, thats dependant on X.
For example, if i want Y_a to be all of the y values that are equal to or greater than x = -4 it would be:
Y_a = -7, -6, 0, 6, 7, 8, 9, 10
If i want Y_a to be equal to Y numbers when x is less than -2 it would be:
Y_a = -10, -9, -8, -7
Does that make sense?
  1 件のコメント
Andrew Lackey
Andrew Lackey 2021 年 9 月 2 日
For example I am trying to run this code:
Y_a = Y(X==[0:1]);
Can I use an ==(range)?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2021 年 9 月 2 日
編集済み: Matt J 2021 年 9 月 2 日
X = [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10];
Y = [-10, -9, -8, -7, -6, 0, 6, 7, 8, 9, 10];
Y_a=Y(-4<=X & X<=8)
Y_a = 1×7
-7 -6 0 6 7 8 9

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by