简体   繁体   English

如何在MATLAB中由3个1d数组组成3d数组?

[英]How to compose a 3d array from 3 1d arrays in MATLAB?

My code is as follows: 我的代码如下:

a = [.325 81 14; .272 105 26; .310 130 35];
b = [.305 75 18; .250 91 23; .285 126 41];
c = [.315 88 15; .265 95 21; .297 113 31];
abc(:,:,1) = a;
abc(:,:,2) = b;
abc(:,:,3) = c;

Essentially, what I want to do is make abc a 3d array of a , b and c with a on the first page, b on the second page, and c on the third page. 从本质上讲,我想要做的就是abc的3D阵列abca在第一页上, b在第二页上,并c第三页上。 However, when I input this into the command window, I get the following error: 但是,当我将其输入命令窗口时,出现以下错误:

Subscripted assignment dimension mismatch. 下标分配尺寸不匹配。

What's wrong with what I'm doing? 我在做什么错了? I read a lot of similar posts where what I wrote was suggested, but my code doesn't seem to work. 我读了很多类似的帖子,这些帖子都建议了我写的内容,但是我的代码似乎不起作用。

It's possible the variable abc already exists in your workspace, which would give you the error you're seeing. 您的工作空间中可能已经存在变量abc ,这将使您看到错误。 A better way of creating your 3D matrix is to use the cat command: 创建3D矩阵的更好方法是使用cat命令:

abc = cat(3,a,b,c);

cat concatenates the specified variables along the specified dimension (in this case the 3rd dimension). cat将指定的变量沿指定的维(在本例中为第3维)连接在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM