フィルターのクリア

Indexing a 3D matrix with a 2D matrix

1 回表示 (過去 30 日間)
NICHOLAS CIMASZEWSKI
NICHOLAS CIMASZEWSKI 2020 年 12 月 25 日
編集済み: Catalytic 2020 年 12 月 25 日
I have a 3D matrix of all zeros, L, of size G_ by H by N.
temp is a 3D matrix of all possible length G binary words which sum to less than gamma, replicated N times. Therefore temp is of size G_ by G by N (where technically G_ is 2^G minus GchooseG minus Gchoose(G-1) minus...Gchoose(gamma+1), but this should be unimportant to our application).
temp = dec2bin(0:2^G-1)-'0'; % (2^G, G)
temp((sum(temp,2)>gamma),:) = []; % (G_, G)
temp = repmat(temp,1,1,N); % % (G_, G, N)
L = zeros(size(temp,1),H,size(temp,3)); % (G_, H, N)
units is a matrix of size G by N. I want to use units to determine which columns of L to change from 0s. This worked well for N=1, but I'm trying to vectorize this to work across multiple datapoints. I tried the following:
L(:,units) = temp;
But L(:,units) collapses down to size (G_, G*N) instead of (G_,G,N), and so there is a size mismatch.
I want L to equal an array which is N slices, where in the i-th slice (out of N), the G columns specificed by the i-th column (out of N) in units is assigned to the i-th slice (out of N) of temp.
This may be confusing – can anybody help me? I feel like there should be a vectorizable solution but I can't find one.
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 25 日
if you want help, then you need to make it easy to be helped.
Stephen23
Stephen23 2020 年 12 月 25 日
You will probably need to convert to linear indices using

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

回答 (1 件)

Catalytic
Catalytic 2020 年 12 月 25 日
編集済み: Catalytic 2020 年 12 月 25 日
units=sub2ind([G,N],units,repmat(1:N,G,1) );
L(:,units)=temp(:,:);

カテゴリ

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