3D Submatrices extraction by indexing the 3rd dimension

2 次查看(过去 30 天)
I have a structure array (a_struct) with 2 fields:
a_struct.m= 370x690x109 double
a_struct.i= 109x1 cell. Each cell contains 13 characters, and some of them end with “1” or “2” (e.g., subj01-XXXXt1… subj01-XXXXt2… subj12-XXXXt1, subj12-XXXXt2).
How can I extract two submatrices from “a_struct.m” based on the elements of the third dimension of “a_struct.m (z= 109)” indexed by the last two elements (i.e., “1”, “2”) of the contents of the first dimension of “a_struct.i (x= 109)”? I expect to get something like:
a_substruct.m1= 370x690x30 double
a_substruct.m2= 370x690x40 double
Where the content of “a_substruct.m1” “a_substruct.m2” has been indexed by “a_struct.i”.

采纳的回答

Stephen23
Stephen23 2023-10-16
a_substruct.m1 = a_struct.m(:,:,endsWith(a_struct.i,'1'));
a_substruct.m2 = a_struct.m(:,:,endsWith(a_struct.i,'2'));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by