acces indexes of Multidimensional arrays while using index of elements in a vector?
1 回表示 (過去 30 日間)
古いコメントを表示
i have a vector called L the vector contain indexes
also i need to use those indexes while writing the totl matrix MAT(L) into a multidimantional array by doing this:
all this is inside a loop
for k=1:anynumber
MAT(:,:,k)
i found that the script doesn't write at all to the destination matrics it only write to the index (:,:,1) and the rest are zeros.
H(:,:,length(frequencies))=zeros(max(rx_pos),max(tx_pos));
LinInd=sub2ind(size(H(:,:,length(frequencies))),rx_pos,tx_pos);
H(LinInd)=Escat;
H(:,:,k)=H(LinInd);
0 件のコメント
採用された回答
dpb
2014 年 9 月 17 日
編集済み: dpb
2014 年 9 月 17 日
...the script ... only write[s] to the index (:,:,1)
Yes, because your index-computing expression only addresses a plane in the 3D array, not the whole array. In the expression size(H(:,:,length(frequencies))), the answer is the x,y dimension of a plane so you compute the linear address in the plane, not in the array.
Use
LinInd=sub2ind(size(H),rx_pos,tx_pos,k);
instead for each plane k and then
H(LinInd)=Escat;
where
length(Escat)==length(LinEnd)
You don't need (or want) the subsequent H(:,:,k) assignment at all--that's what the linear addresses will take care of when you convert them to 3D indexing.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!