MATLAB Answers

How to index one array with the index of another array that meets a certain condition

1 ビュー (過去 30 日間)
Kyle Vanlerberghe
Kyle Vanlerberghe 2019 年 11 月 30 日
Commented: Star Strider 2019 年 11 月 30 日
I have two arrays that correspond to variables of a cloud. One is cloud type and the other is effective radius of the cloud droplet.
I want to find the indexes in the cloud type array where cloud type == 8 and then index my cloud droplet radius array to only show the values in the specific index where cloud type == 8. Can anyone help with this?
ex:
cloud_type = [0 0 6 8 8 5 1 8 2 2 8]
radius = [20 13 14 25 30 10 5 27 13 14 25]
out = [25 30 27 25]

  0 件のコメント

サインイン to comment.

採用された回答

Star Strider
Star Strider 2019 年 11 月 30 日
Try this:
cloud_type = [0 0 6 8 8 5 1 8 2 2 8];
radius = [20 13 14 25 30 10 5 27 13 14 25];
out = radius(cloud_type==8)
producing:
out =
25 30 27 25

  2 件のコメント

Kyle Vanlerberghe
Kyle Vanlerberghe 2019 年 11 月 30 日
Didn't think it was this simple. Thank you so much!
Star Strider
Star Strider 2019 年 11 月 30 日
As always, my pleasure!
This code uses ‘logical indexing’. See: Matrix Indexing for details.

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。


Translated by