Search specific layer of multidimensional matrix for range of values?

2 ビュー (過去 30 日間)
Andrew Poissant
Andrew Poissant 2017 年 4 月 12 日
コメント済み: Andrew Poissant 2017 年 4 月 12 日
I have a layered matrix (3 layers) seen below and what I want to do is search for a range of values in the 2nd layer and then the 3rd layer and return the indices where the range of numbers are found. Lets say I have a variable dx that has a range of values and I want to return the indices in the 2nd and 3rd layer which have any of these values. Any ideas on how to do this? I was thinking of using the find command but am not sure how to use that with multidimensional matrices. Don't get bogged down by all of the code for setting up the matrices, it is just a simple 180x180 matrix with random integers and 2 layers with specified values in each. Thanks!
dx = -60:1:55
N11 = randi([1,500],45,45);
N12 = randi([25,1000],45,45);
N13 = randi([100,2200],45,45);
N14 = randi([5,700],45,45);
N21 = randi([100,500],45,45);
N22 = randi([800,3500],45,45);
N23 = randi([1000,10000],45,45);
N24 = randi([15,1000],45,45);
N31 = randi([250,900],45,45);
N32 = randi([5000,11000],45,45);
N33 = randi([1750,9000],45,45);
N34 = randi([25,890],45,45);
N41 = randi([2000,7500],45,45);
N42 = randi([200,2300],45,45);
N43 = randi([25,750],45,45);
N44 = randi([50,1323],45,45);
N = [N11 N12 N13 N14;
N21 N22 N23 N24;
N31 N32 N33 N34;
N41 N42 N43 N44];
H1 = -90:1:90;
H2 = H1(find(H1~=0));
V1 = -90:1:90;
V2 = V1';
V3 = V2(find(V2~=0));
N(:,:,2) = H2(ones(180,1),:);
N(:,:,3) = V3(:,ones(180,1));

採用された回答

Thorsten
Thorsten 2017 年 4 月 12 日
編集済み: Thorsten 2017 年 4 月 12 日
idx2 = ismember(N(:,:,2), dx);
idx3 = ismember(N(:,:,3), dx);

その他の回答 (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