フィルターのクリア

Creating 3D array from 2D with increment

2 ビュー (過去 30 日間)
Jiayun Liu
Jiayun Liu 2022 年 10 月 13 日
コメント済み: Jiayun Liu 2022 年 10 月 13 日
Suppose I have a 2D array of integers A and I want to create another 2D array B = A+1 and I want to combine them into 1 3D array. I will do something like cat(3,A,B). Now I want to add another 2D array C = B+1 to it. The simple way I can think of would be to loop it through a for loop. I was wondering if there are any other way of doing this without using for loop.

採用された回答

Chunru
Chunru 2022 年 10 月 13 日
A = randi([1, 10], [3, 5])
A = 3×5
5 9 3 6 5 7 8 1 8 6 9 3 8 10 1
C = A + reshape(0:2, [1,1,3]) % increment 0, 1, 2 for example
C =
C(:,:,1) = 5 9 3 6 5 7 8 1 8 6 9 3 8 10 1 C(:,:,2) = 6 10 4 7 6 8 9 2 9 7 10 4 9 11 2 C(:,:,3) = 7 11 5 8 7 9 10 3 10 8 11 5 10 12 3
  1 件のコメント
Jiayun Liu
Jiayun Liu 2022 年 10 月 13 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by