Indexing and squeeze function

5 views (last 30 days)
Suha
Suha on 6 Apr 2018

Hello everyone

My question relates to indexing and the squeeze function. I have the following matrices:

Test1: a 3D matrix with dimensions 5x100x54 with data.

Test2: a 2D 5x6 matrix with ones and zeros, providing information on which of the 5 rows relate to the 6 columns.

Test3 = zeros(6, 100, 54);

Example: Test1 = rand(5, 100, 54); Test2 = [ 1 0 0 0 0 0 ; 0 1 0 0 0 0 ; 0 0 1 0 0 0 ; 0 0 0 1 0 0 ; 0 0 0 0 0 1] ;

I would like to use the Test2 matrix to transfer data from Test1 matrix to fill Test3 blank matrix. For example, the first row of Test2 is allocated to the first column of Test2, hence I want all data from Test1(1, :, :) to be filled into Test3(1, :,:). This procedure can happen for:

Test1(2, :, :) = Test3(2, :,:);

Test1(3, :, :) = Test3(3, :,:);

Test1(4, :, :) = Test3(4, :,:);

Since row 5 is allocated to column 6, the last command would be:

Test1(5, :, :) = Test3(6, :,:);

Could someone please tell me how to do this in one go using Test1 and Test2 to fill Test3?

Thank you

Suha

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!