# How to form a Single matrix from Multiple matrices by taking perticular element from each matrix.???

조회 수: 1 (최근 30일)
Maruti Patil 2015년 4월 15일
편집: Maruti Patil 2015년 4월 15일
Suppose I have a loop
for m=1:8;
a=5+m; b=3*m;
A=[a, b a*b; b, a+b, a-b; 2-a, 3+b a]
end
I will get 8 matrices, now I want to take first element of each matrix to form a column matrix of size 8x1. How to do this?? Please help.....Thanks

댓글을 달려면 로그인하십시오.

### 채택된 답변

편집: Michael Haderlein 2015년 4월 15일
I guess this particular definition of A is just an example, right? If it's really about these specific values, the final result will just be
F=(1:8)'+5;
If you cannot take this shortcut, you'll either need to store all A matrices (right now you overwrite them in each iteration) or you save the respective value in each iteration.
Option 1:
A=zeros(3,3,8);
for m=1:8
a=5+m; b=3*m;
A(:,:,m)=[a, b a*b; b, a+b, a-b; 2-a, 3+b a];
end
F=squeeze(A(1,1,:));
Option 2:
F=zeros(8,1);
for m=1:8
a=5+m; b=3*m;
A=[a, b a*b; b, a+b, a-b; 2-a, 3+b a];
F(m)=A(1);
end
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Maruti Patil 2015년 4월 15일
편집: Maruti Patil 2015년 4월 15일
Exact this is what I wanted. Thank you Michael.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by