Filter löschen
Filter löschen

How to make a matrix from several column vectors

40 Ansichten (letzte 30 Tage)
Emilie
Emilie am 7 Aug. 2013
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!

Antworten (3)

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

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by