フィルターのクリア

Use only defined 4D array elements

1 回表示 (過去 30 日間)
Mantas Vaitonis
Mantas Vaitonis 2018 年 7 月 22 日
コメント済み: Mantas Vaitonis 2018 年 7 月 22 日
Hello to All, There is 4D array varcov (NxNxZxL), I need to make other 4D array with the following values:
varcov1=[varcov(1,1,:,:) varcov(2,2,:,:) varcov(3,3,:,:) ..till end(N)];
That result varcov1 would be (1xNxZxL).

採用された回答

Rik
Rik 2018 年 7 月 22 日
The code below should work for you. Since R2016b you can use the line with implicit expansion.
N=3;Z=4;L=6;
varcov=reshape(1:(N*N*Z*L),N,N,Z,L);%generate sample data
inds=bsxfun(@plus,(1:N+1:N^2)',N^2*(0:(Z*L-1)));%find the inds to the diagonal of each slice
%(1:N+1:N^2)'+N^2*(0:(Z*L-1)); with implicit expansion
varcov1=reshape(varcov(inds),1,N,Z,L);
  1 件のコメント
Mantas Vaitonis
Mantas Vaitonis 2018 年 7 月 22 日
Yes this works, thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by