how to fill 3D array with alternate data from another 3D array

3 ビュー (過去 30 日間)
Hugo
Hugo 2022 年 2 月 24 日
コメント済み: Benjamin Thompson 2022 年 2 月 24 日
Hi,
I have a 3D array called data 1, with dimensions (51,1000,50)
I would like to fill another 3D array, called data, with dimensions (27,1000,50). I have written the following code:
data(1:3,:,:)=data1(1:3,:,:)
data(4:6,:,:)=data1(7:9,:,:)
data(7:9,:,:)=data1(13:15,:,:)
data(10:12,:,:)=data1(19:21,:,:)
data(13:15,:,:)=data1(25:27,:,:)
data(16:18,:,:)=data1(31:33,:,:)
data(19:21,:,:)=data1(37:39,:,:)
data(22:24,:,:)=data1(43:45,:,:)
data(25:27,:,:)=data1(49:51,:,:)
The code works ok, but I wonder if there is a more efficient way to code this.
I thank you in advance,
Best regards

採用された回答

Benjamin Thompson
Benjamin Thompson 2022 年 2 月 24 日
This is a partial example but you can use an index vector to designate all the rows you want to copy from data1:
Icopy = [1:3, 7:9];
data(1:6,:,:)=data1(Icopy,:,:)
  1 件のコメント
Benjamin Thompson
Benjamin Thompson 2022 年 2 月 24 日
Extending this example you can collapse your code into one line which will probably be a bit faster also. Just one copy into data.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by