# matrix manipulation

조회 수: 2 (최근 30일)
Raviteja 2011년 9월 22일
>> A
A =
7 0 6
9 8 7
6 9 7
>> B
B =
3 7 0
6 0 0
1 2 8
>> C
C =
6 0 7
3 4 7
9 3 1
I need to have a matrix which have to store like this
>> Vec
Vec =
7 9 6 0 8 9 6 7 7
3 6 1 7 0 2 0 0 8
6 3 9 0 4 3 7 7 1
the above representing, each location element of all mattices are stored as coloumn.
For this I have written a code like this
>> P=reshape(A,[1 9]);
>> Q=reshape(B,[1 9]);
>> R=reshape(C,[1 9]);
>> Vec=[P;Q;R]
Is there any better way to do this?
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Jan 2011년 9월 22일
What do you mean by "better"? Faster or nicer?

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

### 채택된 답변

Fangjun Jiang 2011년 9월 22일
Vec=[A(:) B(:) C(:)]'
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Fangjun Jiang 2011년 9월 22일
You could do that but you'll have hard time to identify the new_matrix in the for-loop because they have different name like A, B, C, etc. or in many case, people name it A1, A2, A3, etc, right? If you really have more than 100 matrices, the right solution is to do it right at the beginning. Instead of using A, B, C, you can define the variable as Vec=zeros(9, 100) and then you avoid the problem. See "How can I create variables A1, A2,...,A10 in a loop?" at http://matlab.wikia.com/wiki/FAQ
Fangjun Jiang 2011년 9월 22일
@Walter, I need to learn from you how to put that hyper-link in place with the right FAQ item at the top of the page. This question has popped up twice just this morning. Right now, I made a bookmark out of your hyper-link.

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

### 카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by