Matlab中矩阵到矢量的转换 [英] Matrix to Vector Conversion in Matlab

查看:428
本文介绍了Matlab中矩阵到矢量的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MxN矩阵,并希望将矩阵中该行的所有元素作为向量的元素转换为向量MNx1.

I have a MxN Matrix and would like to convert into a vector MNx1 with all the elements of the row from the Matrix as the elements of the Vector.

我尝试使用reshape,但未成功.

I tried using reshape but I was not successful.

这是小代码段和预期结果.

Here is the small code snippet and the expected result.

  S=[0     1
     1     0
     1     1
     1     1 ]

预期结果:

S_prime= [ 0 1 1 0 1 1 1 1]

P.S:使用循环和串联不是一种选择,我确信有一种我不知道的简单易用的技巧.

P.S: Using a loop and concatenation is not an option, I am sure there is a easy straight forward technique, which I am not aware.

谢谢

推荐答案

您可以尝试转置S并使用(:)

You could try transposing S and using (:)

S = S'
S_prime = S(:)

或行向量:

S_prime = S(:)'

这篇关于Matlab中矩阵到矢量的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆