简体   繁体   中英

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. 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. A better way of creating your 3D matrix is to use the cat command:

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

cat concatenates the specified variables along the specified dimension (in this case the 3rd dimension).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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