MATLAB添加不同维度的矩阵 [英] MATLAB adding matrices with different dimensions

查看:1135
本文介绍了MATLAB添加不同维度的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在添加两个具有不同大小的数组时遇到了麻烦.当我在该站点上进行一些浏览时,似乎大多数问题都涉及具有不同大小的向量,而不是涉及行和列中具有多个维度的实际矩阵.

I'm having trouble adding two arrays with different sizes. When I explored a bit on this site it seemed like most questions involved vectors with different sizes, but not actual matrices with multiple dimensions in both rows and columns.

我知道在数学上添加不同维度的矩阵没有意义".这只是我用来使代码工作更轻松的工具,但这是一个问题:

I know it "doesn't make sense" mathematically to add matrices with different dimensions. It's just a tool I'm using to make code work easier, but here goes the question:

A = magic(4);
B = magic(3);
C = A + B

那基本上就是我想要做的.我只想使B在第4行和第4列具有零,然后可以具有相同的尺寸并将其相加.但是我该怎么做呢?预先感谢=)

That is basically what I want to do. I just want to make B have zeros along the 4th row and 4th column, and then I could have the same dimensions and add them. But how do I do it? Thanks in advance =)

另外,特别是,我想以一种方式将B添加到A,以便A的原始3x3基本上移过" 1列,但保持在同一行.

Also, in particular I would like to add B to A in a way so the original 3x3 from A basically "moves over" 1 column but stays in the same row.

推荐答案

在将A和B相加之前,用零填充数组B. 使用功能"padarray"

pad the array B with zeros before adding A and B. Use the function "padarray"

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

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