3 dimension array?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi, How to write 3 or 4 dimansion array?
Thanks, Henry
채택된 답변
2 개 추천
Any internet search engine will give these pages at the top of the search results:
MATLAB's documentation is really useful and readable. It tells us how to use MATLAB. It has working examples too. You can search it using your favorite internet search engine: this will find the official, correct and recommended ways of using MATLAB. The first link above includes the title "Creating Multi-Dimensional Arrays" at the top of the page. Perhaps you might like to read this.
Here are three easy ways to create ND arrays:
- indexing:
>> A(:,:,2) = [1,2;3,4];
>> A(:,:,1) = [9,8;7,6]
A(:,:,1) =
9 8
7 6
A(:,:,2) =
1 2
3 4
- reshape:
>> X = [9,7,8,6,1,3,2,4];
>> reshape(X,2,2,2)
ans(:,:,1) =
9 8
7 6
ans(:,:,2) =
1 2
3 4
- cat:
>> X = [1,2;3,4];
>> Y = [9,8;7,6];
>> cat(3,Y,X)
ans(:,:,1) =
9 8
7 6
ans(:,:,2) =
1 2
3 4
댓글 수: 6
Henry Buck
2015년 9월 11일
Thanks a lot, Henry
Luis
2026년 6월 15일 20:17
in this example you shows a 2 dimensional array?
Steven Lord
2026년 6월 15일 20:44
Those approaches do start off using 2-dimensional arrays.
The indexing approach assigns those 2-dimensional arrays into segments of a 3-dimensional array.
The reshape approach "folds" the 2-dimensional arrays in the third dimension. [If you've ever seen those toys that are snakes built of plastic or wooden blocks, picture folding one of those into a cube form. I'm thinking of something like a Rubik's Snake.]
The cat approach stacks two 2-dimensional arrays on top of one another, like snapping one Lego block on top of another Lego block.
A fourth approach, that's somewhat related to the indexing approach, is the allocate-and-fill approach. In this you "set up shelves" using a function like zeros, ones, etc. then assign values into the array like putting items on the shelves.
shelves = zeros(2, 3, 4)
shelves =
shelves(:,:,1) =
0 0 0
0 0 0
shelves(:,:,2) =
0 0 0
0 0 0
shelves(:,:,3) =
0 0 0
0 0 0
shelves(:,:,4) =
0 0 0
0 0 0
shelves(1, 2, :) = [1 2 3 4]
shelves =
shelves(:,:,1) =
0 1 0
0 0 0
shelves(:,:,2) =
0 2 0
0 0 0
shelves(:,:,3) =
0 3 0
0 0 0
shelves(:,:,4) =
0 4 0
0 0 0
I've essentially put stuff in the "middle of the back of each shelf" with the assignment statement. This approach makes sure I have the right sized "set of shelves" from the get-go without the trick the indexing approach used, where it put items on the second shelf first (to make sure you got a shelving unit with at least two shelves.)
Walter Roberson
2026년 6월 16일 18:10
To be explicit:
There is no MATLAB notation to directly represent 3 or more dimensions of an array. For example,
A = [[1 2 3], [4 5 6]]
does NOT create a 2 x 1 x 3 array, and there is no notation similar to
A = [1 2 3 ## 4 5 6]
to create a 1 x 3 x 2 array.
The closest MATLAB notation to that is
A = cat(3, 1 2 3, 4 5 6)
The direct MATLAB notation only extends to 2 dimensions.
Stephen23
2026년 6월 17일 3:15
A = cat(3, [1,2,3], [4,5,6])
Walter Roberson
2026년 6월 17일 5:05
Opps,
A = cat(3, [1 2 3], [4 5 6])
it is!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 LEGO MINDSTORMS EV3 Hardware에 대해 자세히 알아보기
태그
아직 태그를 입력하지 않았습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
