将向量存储为矩阵中矩阵的(i,j)项 [英] store a vector as an (i,j) entry of a matrix in matlab

查看:154
本文介绍了将向量存储为矩阵中矩阵的(i,j)项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在做的项目的简化版本.我可以使用其他方法解决此问题.我只是想知道,是否可以在matlab中执行此操作? 我想将1 * 2向量[100,100]存储到给定矩阵a的(1,1)项中.以下是代码. a = zeros(2,2); a(1,1)= [100,100]; 然后,我得到下标的分配维度不匹配错误. 我可以改用单元格数组.但是,与矩阵相比,用于单元阵列的函数并不多(如tril).因此,我只是想知道,是否有人知道如何处理这种情况,或者这只是一个微不足道的案例,根本无需提及.非常感谢您的时间和关注.

This is a simplified version of the project I am doing. I can get around this using other methods. I was just wondering, is it possible to do this in matlab ? I want to store a 1*2 vector [100,100] to the (1,1) entry of a given matrix a. The following is the code. a=zeros(2,2); a(1,1)=[100,100]; Then I get Subscripted assignment dimension mismatch error. I could use cell array instead. But there are not so many handy functions (like tril) for cell array compared with matrix. So, I was just wondering, does anyone know how to handle this situation or this is just a trivial case not need to mention at all. Many thanks for your time and attention.

推荐答案

如果您已经知道向量的长度,则可以使用3-d矩阵而不是2-d矩阵.

You can use 3-d matrix instead of 2-d matrix if you already know the length of vector.

a = zeros (2,2,2) ;
a(1,1,:) = [100, 100] ; 

a =  [];
a (1,1,:) = [100,100];

在上面的示例中,您必须自己处理索引,矩阵a可以是任意维度.

In above example, you have to take care of indexing by yourself and matrix a can be in arbitrary dimensions.

这篇关于将向量存储为矩阵中矩阵的(i,j)项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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