将新列添加到MATLAB中的现有矩阵? [英] Add a new column to an existing matrix in MATLAB?

查看:537
本文介绍了将新列添加到MATLAB中的现有矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的矩阵,其中一列是日期,另一列是我必须对其执行一些操作的数量.我想在现有矩阵中添加第三列.我打算通过将第三列公式化为列向量,然后将其添加到我现有的矩阵中来解决这个问题(尽管我不确定如何将另一列添加到矩阵中,任何帮助将不胜感激!)

I have a matrix with two columns, one of which is the date and another of which is a quantity that I have to perform some operations on. I wanted to add a third column to my existing matrix. I was going to go about this by formulating the third column as a column vector, and then adding it on to my existing matrix (although I am not sure how to add another column onto a matrix either- any help would be much appreciated!)

对于我的第三列,我想将399除以现有矩阵中的(180,2)元素,然后将新矩阵中的每个元素乘以现有矩阵第二列中的值乘以这个数量.我的代码是:

For my third column, I wanted to divide 399 by the (180,2) element in my existing matrix, and then each element in my new matrix would be formed by multiplying the value in the second column of the existing matrix by this quantity. My code was:

a3=([:,a(:,2).*399/a(180,2)])

我现有的矩阵是

apre=dlmread('filename.csv',',',1,0);
a=[apre(1:180,:)]

推荐答案

我不确定如何在矩阵上添加另一列

I am not sure how to add another column onto a matrix

如何在现有矩阵中添加列?

How to add a column to an existing matrix ?

示例:

      1 1 1
Mat = 1 1 1
      1 1 1

        3
Col =   3
        3


Mat = [Mat, Col];


          1 1 1 3
   Mat =  1 1 1 3
          1 1 1 3



apre=dlmread('filename.csv',',',1,0);
a=[apre(1:180,:)]

a is a matrix of size 180x2 iff filename.csv has 2 columns.

a = [a, a(:, 2).*399/(a(180, 2))];

这篇关于将新列添加到MATLAB中的现有矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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