3 dimension array?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Hi, How to write 3 or 4 dimansion array?
Thanks, Henry
採用された回答
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
