Printing 2 column vectors of different sizes

8 vues (au cours des 30 derniers jours)
Ahmad Alalyani
Ahmad Alalyani le 28 Juil 2018
Commenté : Image Analyst le 3 Août 2018
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)]

Réponses (1)

Rik
Rik le 28 Juil 2018
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 commentaires
Rik
Rik le 3 Août 2018
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 le 3 Août 2018
Ahmad, leave off the last semicolon to see them reported to the command window. You can also use fprintf() if you want.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by