2D array?

Hi, I have a 3 by 3 matrix X(a,b,c)
I tried to define a submatrix
S = X(3,:,:);
but matlab keeps saying that S is not a 2D array. Why is that so?
Thank you very much.
Added: class(S) apparently is "double" but I don't understand why. How might I make S into a 2D array?

4 个评论

Oleg Komarov
Oleg Komarov 2012-4-15
X is a 3D array if you write it in that way: X(a,b,c).
what whos on X returns?
Werner
Werner 2012-4-15
Thank you, @Oleg, but wouldn't S (havin one coordinate fixed), be a 2D array?
Werner
Werner 2012-4-15
@Oleg: Also, if S as defined is not a 2D array, how might I define a 2D array that is essentially the same thing as S? Thanks.
Werner, X(3,:,:) is a 1 x something x something array. See IA's solution.

请先登录,再进行评论。

 采纳的回答

Image Analyst
Image Analyst 2012-4-15

0 个投票

Use squeeze(). This works fine for me:
s3D = rand(4,3,2)
s2D = squeeze(s3D(2,:,:))
s3D(:,:,1) =
0.5103 0.0183 0.1749
0.6590 0.7794 0.2998
0.8773 0.6623 0.7778
0.0790 0.9458 0.6653
s3D(:,:,2) =
0.2475 0.0516 0.3926
0.7406 0.1848 0.6212
0.0042 0.7256 0.4685
0.5316 0.3404 0.1957
s2D =
0.6590 0.7406
0.7794 0.1848
0.2998 0.6212
You can see that it took row 2 out of the first plane, and row 2 out of the second plane, and gave you a 3 by 2 array, just what it should have.

更多回答(0 个)

类别

产品

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by