matlab - Extract the diagonal of data and regroup the numbers -


i have data shown in below:

for a=1:2     b=1:3         m{a,b}=zeros(3,3)     end  end  m{1,1}=[6 1 1;1 7 1;1 1 6]; m{1,2}=[3 2 2;2 5 2;2 2 6]; m{1,3}=[5 3 3;3 9 3;3 3 7];  m{2,1}=[2 4 4;4 5 4;4 4 8]; m{2,2}=[2 1 1;1 6 1;1 1 5]; m{2,3}=[6 2 2;2 7 2;2 2 8]; 

i take diagonal of each set of data , regroup these numbers.for example,

%result  row_1_1=[6;3;5]  %which 6 m{1,1}(1,1), 3 m{1,2}(1,1) , 5 m{1,3}(1,1)  row_1_2=[7;5;9]  %which 7 m{1,1}(2,2), 5 m{1,2}(2,2) , 9 m{1,3}(2,2)  row_1_3=[6;6;7]  %which 6 m{1,1}(3,3), 6 m{1,2}(3,3) , 7 m{1,3}(3,3)  row_2_1=[2;2;6]  %which 2 m{2,1}(1,1), 2 m{2,2}(1,1) , 6 m{2,3}(1,1) 

and on.

any idea how these result??thanks~

you do:

row_result = zeros(a,b,3); i=1:a     j=1:b         k = 1:3             row_result(i,k,j) = m{i,k}(j,j);         end     end end 

for sample data provided, yield results follows:

>> row_result(1,:,1)  ans =       6     3     5  >> row_result(1,:,2)  ans =       7     5     9  >> row_result(1,:,3)  ans =       6     6     7  >> row_result(2,:,1)  ans =       2     2     6 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -