简体   繁体   English

如何在水平矩阵中显示垂直矩阵?

[英]how to display my vertical matrix in an horizontal matrix?

In one file 'file.mat', I have a matrix which its size is (1,100), it is written vertically like this: 在一个文件“ file.mat”中,我有一个矩阵,其大小为(1,100),它像这样垂直写入:

  M1 =

     Columns 1 through 26:

        6   13    3   15   13   12    8    5    5    1   11    8    5    9    1    7   15    9    2    5    7    7    3    9    0   13

     Columns 27 through 52:

        4    5    7    2    6    6    2    7   12    5    5   12    0    6   11   15    1    2   12    9   13    9    7   13    2    2

     Columns 53 through 78:

        7   15    4   15    5   12    5   12   14    3   10   15   12    5    5   15    3    3    9    3    6    0   13   13    8    5

     Columns 79 through 100:

        2   10    0    8    5    5    9    8   13   14   15   14   10    6    7    8    9   10   14    5    2    5

How to change it in an horizontal Matrix? 如何在水平矩阵中更改它?

You can use M1.' 您可以使用M1.' or permute(M1,[2 1]) . permute(M1,[2 1]) If you want all numbers to be in one horizontal line (ie to be an vector) you can use reshape(M1, [1,100]) 如果您希望所有数字都在一条水平线上(即作为矢量),则可以使用reshape(M1, [1,100])

What you have is a horizontal vector, but MATLAB displays it like that so that you can easily see where each element belongs. 您拥有的是一个水平向量,但是MATLAB会像这样显示它,以便您可以轻松查看每个元素所属的位置。 I guess what you want is to display the vector as a horizontal vector, so that you can copy-paste it. 我猜您想要的是将向量显示为水平向量,以便您可以将其复制粘贴。 If so: 如果是这样的话:

You can use sprintf if you want to display this as a long vector. 如果要将其显示为长向量,可以使用sprintf

sprintf('%i ', M)
ans =   
35 3 31 8 30 4 1 32 9 28 5 36 6 7 2 33 34 29 26 21 22 17 12 13 19 23 27 10 14 18 24 25 20 15 16 11 

Or if you need the brackets: 或者,如果您需要括号:

['[', sprintf('%i ', M), ']']    
ans =    
[35 3 31 8 30 4 1 32 9 28 5 36 6 7 2 33 34 29 26 21 22 17 12 13 19 23 27 10 14 18 24 25 20 15 16 11 ]

You can also have it tab-separated: sprintf('%i\\t', M) , or with commas: sprintf('%i,', M) . 您也可以使用制表符分隔它: sprintf('%i\\t', M)或逗号: sprintf('%i,', M)

If you want to reshape your horizontal vector to a vertical , you can do: 如果要将水平矢量重塑为vertical ,可以执行以下操作:

M = M.';

Note that ' is NOT the transpose operator, .' 注意, '不是转置运算符” .' is. 是。 If you have a vector, but don't know whether it's horizontal of vertical, use the following notation: M = M(:).' 如果您有矢量,但不知道它是否为垂直的水平,请使用以下表示法: M = M(:).' , or reshape(M, 1, []) . reshape(M, 1, [])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM