Printing 2 column vectors of different sizes

3 次查看(过去 30 天)
I wrote this code :
j = 1;
for i = 1:h-1
if T(i,1)<0 && T(i+1,1)>0
xu(j)= x(i+1);
j = j+1;
end
if T(i,1)<0 && T(i+1,1)>0
xv(j)= x(i+1);
j = j+1;
end
end
My outputs are xu and xv.
xu comes as 5x1 column vector.
xv comes as 6x1 column vector.
How can I print them side by side in order to read them easily.
I want them to be printed as:
[xu(1,1) xv(1,1);xu(2,1) xv(2,1);xu(3,1) xv(3,1);xu(4,1) xv(4,1);xu(5,1) xv(5,1);0 xv(6,1)]

回答(1 个)

Rik
Rik 2018-7-28
This solves it for the general case:
Out=zeros(max([numel(xv) numel(xu)]),2);
Out(1:numel(xu),1)=xu;
Out(1:numel(xv),2)=xv;
  2 个评论
Rik
Rik 2018-8-3
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.
Image Analyst
Image Analyst 2018-8-3
Ahmad, leave off the last semicolon to see them reported to the command window. You can also use fprintf() if you want.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by