如何将向量存储到矩阵中
123次观看(最近30天)
显示较旧的评论
我有一个向量,在每次迭代时都采用不同的值,我想将向量的结果存储在矩阵示例中迭代1 a = [1 2 3 4]迭代2 a = [5 6 7 8],所以我想要一个结果矩阵:结果= [1 2 3 4;5 6 7 8]
0评论
答案(5)
图像分析师
2020年8月20日
If the "A" is really as predictable as you implied in your comment to Ruger28 (and not general as I assumed in my Answer), and you want a vectorized way to do it, you can use reshape:
计算= 5;无论您想要/需要什么%。
结果= reshape([1:计数*4]',4,[])'
你得到:
结果=
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
当然,此矢量化版本是更MATLAB-Y的方法。根本不需要循环。(这种方式还使用您的首选和更好的变量名称“结果”。)