How to make a matrix from several column vectors

37 次查看(过去 30 天)
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