필터 지우기
필터 지우기

Reshaping a square matrix to a vector

조회 수: 6 (최근 30일)
Esteban
Esteban 2012년 3월 23일
Hi, I need to convert a 10 by 10 matrix into a 100 by 1 matrix by concatenating each column to the bottom of the preceding one. For example:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
into [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]'
I've tried using reshape but I'm not getting what I want... moreover, I'm trying to use a for loop but can't seem to get it right.
Any help is much appreciated.
Thanks!
-E

채택된 답변

James Tursa
James Tursa 2012년 3월 23일
This matches your words:
A = rand(10,10);
B = A(:); % one way
B = reshape(A,100,1); % another way
This matches your example:
B = reshape(A.',100,1);

추가 답변 (1개)

Esteban
Esteban 2012년 3월 26일
Woops, my fault... yes I meant:
[1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16]'
I tried it and it works.
Thanks for your help!
-E

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by