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 Kommentare

Oleg Komarov
Oleg Komarov am 15 Apr. 2012
X is a 3D array if you write it in that way: X(a,b,c).
what whos on X returns?
Werner
Werner am 15 Apr. 2012
Thank you, @Oleg, but wouldn't S (havin one coordinate fixed), be a 2D array?
Werner
Werner am 15 Apr. 2012
@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.
Walter Roberson
Walter Roberson am 15 Apr. 2012
Werner, X(3,:,:) is a 1 x something x something array. See IA's solution.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 15 Apr. 2012

0 Stimmen

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.

Weitere Antworten (0)

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by