Adding matric to an empty matric

Hello,
I have an empty matrix
em = [];
I also have other matrices x1, x2 and x3;
t = 0:1/32798:0.25-1/32798;
x1 = sin(2*pi*1356*t) + sin(2*pi*297*t);
x2 = sin(2*pi*3336*t) + sin(2*pi*997*t);
x3 = sin(2*pi*2336*t) + sin(2*pi*497*t);
I would like to add x1, x2, and x3 into em.
since x1, x2 and x3 are 1 x 8199. I would like to put x1 in row1, x2 in row 2 and x3 in row 3.
How do I do this?
Thank you.

 採用された回答

Matt J
Matt J 2012 年 11 月 27 日
編集済み: Matt J 2012 年 11 月 27 日

0 投票

em=[x1;x2;x3]
or
em=vertcat(x1, x2, x3)
or
em = cat(1,x1,x2,x3);

6 件のコメント

kyin gab
kyin gab 2012 年 11 月 27 日
I was about to modify my question when I saw you have already answered it.
Well, I meant to say how can I add to em using a for loop. That is for the first iteration of the for loop,x1 wiil be added then for the second, x2 will be added.
Thanks.
Matt J
Matt J 2012 年 11 月 27 日
em=zeros(3, 8199); %pre-allocate!!!
newrows=[x1;x2;x3];
for i=1:3
em(i,:)=newrows(i,:);
end
kyin gab
kyin gab 2012 年 11 月 27 日
編集済み: kyin gab 2012 年 11 月 27 日
ok it worked. If I want to plot them against t on the same graph how will I do it?
plot(t,em); ?
Matt J
Matt J 2012 年 11 月 27 日
plot(t, x1,t, x2,t,x3)
kyin gab
kyin gab 2012 年 11 月 27 日
I want to plot them from em. This is because I will be using a for loop to enter the values of em and the size is not fixed.
Matt J
Matt J 2012 年 11 月 27 日
args=[repmat({t},size(em,1),1), num2cell(em,2)].';
plot(args{:});

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2012 年 11 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by