Azzera filtri
Azzera filtri

How to make a matrix from several column vectors

40 visualizzazioni (ultimi 30 giorni)
Emilie
Emilie il 7 Ago 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!

Risposte (3)

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

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by