필터 지우기
필터 지우기

How to make a matrix from several column vectors

조회 수: 40 (최근 30일)
Emilie
Emilie 2013년 8월 7일
Hi, Can anybody help me with this? I have 30 column vectors: norm(:,1,stn), where stn = 1:30. How do I put these 30 column vectors into one matrix? So that I get
a = [norm(:,1,1) norm(:,1,2) norm(:,1,3) etc.] ???
Thanks!

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 7일
편집: Azzi Abdelmalek 2013년 8월 7일
m=size(norm,1);
a=zeros(m,30);
for k=1:30
a(:,k)=norm(:,1,k);
end
%or
a=reshape(norm(:,1,1:30),[],30)

kjetil87
kjetil87 2013년 8월 8일
When you say "into one matrix" do you want a two dimensional matrix as Azzi proposed? If you want one long vector as the line
a = [norm(:,1,1) norm(:,1,2) norm(:,1,3) etc.]
indicates you can actually just type
a=norm(:);
Since matlab will allways read columnwize.This will produce a column vector. If you want a row vector instead type
a=norm(:).';
If you want a 2D matrix you can also use this method but then you need to pre allocate a zero matrix.
m=size(norm,1);
a=zeros(m,30);
a(:)=norm(:);

Andrei Bobrov
Andrei Bobrov 2013년 8월 8일
norm1 = randi(10,5,1,30); % Let
a = squeeze(norm1);

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by