I have multiple 9 x 96 x 14 x 1356 matrixes. I want to find when one of them meets a certain criteria and then select the same indexes on the other matrixes.
I did this and looked liked it worked...
idx = find(neutral<24.5);
[r, c, v, l] = ind2sub(size(neutral),idx);
With this, I get a r, c, v, l with 4411652 x 1 each, instead of a 4D logical matrix, which was what I was expecting (like what happens with a 2D matrix when using find).
I tried using those indexes to cut my other variables, but I could't do it.
temp_AT = temp(r,c,v,l);
Thanks!

6 件のコメント

Rik
Rik 2019 年 8 月 5 日
Do you really need it to be 4D logical? If not, you can directly use the indices.
Thaís Lobato Sarmento
Thaís Lobato Sarmento 2019 年 8 月 5 日
Not necessarily... I just need a way to use the information (neutral<24.5) to select the other 4D variables... And this is the way I know how to do it (in 2D matrixes). But I am open to suggestions...
Adam Danz
Adam Danz 2019 年 8 月 5 日
編集済み: Adam Danz 2019 年 8 月 5 日
d = other4Darray(neutral < 24.5) %assuming both arrays are same size
% d will be a vector
idx = find(neutral<24.5);
% d(i) comes from the index idx(i)
Thaís Lobato Sarmento
Thaís Lobato Sarmento 2019 年 8 月 6 日
this kind of works... but I get the same result as I put in my question (4411652 x 1 matrix). I need it to keep the 4D format...
Adam Danz
Adam Danz 2019 年 8 月 6 日
When you remove or isolate elements from an array, they no longer have the same shape unless you're indexing all of the data. Here's a simple example.
d = [2, 3, 2;
5, 2, 2];
idx = d == 2; %same shape as d
d(idx) % a vector with 4 elements, not 6!
If you're trying to get rid of data and maintain the shape of the data, you can replace unwanted data with NaNs (or any other value).
d = [2, 3, 2;
5, 2, 2];
idx = d == 2; %same shape as d
d(~idx) = NaN; % same shape as d!
Thaís Lobato Sarmento
Thaís Lobato Sarmento 2019 年 8 月 6 日
Thanks, this worked!

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

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 5 日

2 投票

neutral<24.5
is the 4d logical matrix. No need for find()

2 件のコメント

Adam Danz
Adam Danz 2019 年 8 月 5 日
+1 (moving my inferior answer here)
idx = find(neutral < 24.5);
logIdx = false(size(neutral)); %Logical index (default: all false)
logIdx(idx) = true; %Set 'idx' indices as true
Thaís Lobato Sarmento
Thaís Lobato Sarmento 2019 年 8 月 6 日
Thank you! This also worked!

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

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by