How to find out the index number of particular value from three dimensional matrices

A(:,:,1)= [1 0 0
0 1 0
1 0 1]
A(:,:,2)= [1 1 0
1 0 1
0 1 1]
A(:,:,3)= [1 0 1
0 0 1
1 1 0]
for i1=1:3
for j1=1:3
[a1(:,j1),b1(:,j1),c1(:,j1)]= ind2sub(size(A)==1,j1);
[a2(:,j1),b2(:,j1),c2(:,j1)]= ind2sub(size(A)==1,j1);
[a3(:,j1),b3(:,j1),c3(:,j1)]= ind2sub(size(A)==1,j1);
end
end
I have this three dimesional matix with different indices of three matrices. Now I want to find out the the rowcolumn and index number of each index of the matrices and store the value of 1st column of three matrices in one matrix and like so on. Means in a1 matrix 1st column of three signal should be stored. But the code is not working. Please suggest me to resolve this problem.

 Accepted Answer

V = cell(size(A, 3), 1);
for k = 1 : size(A, 3)
[R, C] = find(A(:, :, k));
V{k} = [R, C];
end
celldisp(V) % V{1} first matrix indicating the first page and so on

3 Comments

Sorry I am not asking it properly. i want to find out the the row number of value 1 every 1st column of three signal should be stored in a1 with its row number and others are so on . But the code is not working. Please help me to solve out the problem
for i1=1:3
for j1=1:3
[a1(:,j1),b1(:,j1),c1(:,j1)]=find(A(:,1,j1)==1);
[a2(:,j1),b2(:,j1),c2(:,j1)]=find(A(:,2,j1)==1);
[a3(:,j1),b3(:,j1),c3(:,j1)]=find(A(:,3,j1)==1);
end
end
I have one more doubt.
I have another matrix C with dimension 3 by 3. Now for each column of the matrix C, I want to store the value whose index number or row number is matched with matrix V. Means for same row number I want to find out the value from C for each column when the row number will matched with V matrix for each cell.

Sign in to comment.

More Answers (0)

Asked:

AS
on 14 Sep 2020

Commented:

AS
on 15 Sep 2020

Community Treasure Hunt

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

Start Hunting!