MATLAB: printing comparative columns for elements from different vectors

I am trying to print comparative columns to compare elements with the same index of two or three different vectors. I will illustrate my question with the following example

>> a = [5.47758 7.46578 3.45323]
a =

5.4776    7.4658    3.4532

>> b = [5.65432 4.45678 2.34789]

b =

5.6543    4.4568    2.3479

Now if i write

>> sprintf('%.2f %.2f\n',a, b)

I get the following response from Matlab

ans =
5.48 7.47
3.45 5.65
4.46 2.35`

But how I would like to see this presentation of meanings is

ans =
5.48 5.65  
7.47 4.46 
3.45 2.35

How can I use the sprintf function (or another function or method) to get the above view? Thank.

+3
source share
2 answers

You can solve this problem concatenation a and bone input argument of the matrix 2 to 3:

>> sprintf('%.2f %.2f\n',[a; b])

ans =

5.48 5.65
7.47 4.46
3.45 2.35

SPRINTF , ( ) , . a , b a b.

+3

"" , MATLAB Console ( "Command Window" ):


a = [5.47758 7.46578 3.45323];
b = [5.65432 4.45678 2.34789];

c = [a',b']; % Transposing each row vector into a column vector before forming a matrix

c =

    5.4776    5.6543
    7.4658    4.4568
    3.4532    2.3479

, , "sortrows" (. "" : "help sortrows" "doc sortrows" ).

0

Source: https://habr.com/ru/post/1774994/


All Articles