Matrix indexing: fast way to compute covariance of N different MxL matrices that are saved in NxMxL matrix

5 ビュー (過去 30 日間)
T
T 2017 年 3 月 24 日
編集済み: Matt J 2017 年 3 月 24 日
I have a NxMxL matrix called bigmatrix That I can split into N temporary submatrices. On each temporary submatrix I need to calculate the covariance. I do this in the following way:
for k=1:N
submatrix=squeeze(bigmatrix(k,:,:)).';
R=submatrix*submatrix';
end
The covariance is calculated really fast. My problem is loading the submatrix. This takes 6 seconds. Is there a faster way to do this? The matrix indexing is slowing me down a lot.
Thanks!

回答 (1 件)

Matt J
Matt J 2017 年 3 月 24 日
編集済み: Matt J 2017 年 3 月 24 日
Using MTIMESX ( Download ), we can eliminate the loop altogether,
data=permute(bigmatrix,[2,3,1]);
R=mtimesx(data,'t',data);
If you build bigmatrix as MxLxN in the first place, you can avoid the overhead of permute(). Even without mtimesx, I expect an MxLxN data organization will accelerate your loop
for k=1:N
submatrix=data(:,:,k);
R=submatrix.'*submatrix;
end

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by