Clear Filters
Clear Filters

How to make a matrix from several column vectors

40 views (last 30 days)
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!

Answers (3)

Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2013
Edited: Azzi Abdelmalek on 7 Aug 2013
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 on 8 Aug 2013
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 on 8 Aug 2013
norm1 = randi(10,5,1,30); % Let
a = squeeze(norm1);

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!