Filter löschen
Filter löschen

acces indexes of Multidimensional arrays while using index of elements in a vector?

1 Ansicht (letzte 30 Tage)
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);

Akzeptierte Antwort

dpb
dpb am 17 Sep. 2014
Bearbeitet: dpb am 17 Sep. 2014
...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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by