Constructing full matrix like a sparse one

조회 수: 3 (최근 30일)
Ife
Ife 2023년 8월 3일
댓글: Ife 2023년 8월 3일
I was wondering if there was a way to construct a full matrix like you would a sparse matrix.
I'm working with single photon data so my images are histograms of counts that I read from the bits in my data stream. Due to how sparse works I've found that it is faster to do my histogramming using sparse with 4 inputs, S = sparse(i,j,v,m,n), as it sums values that have the same indicies but this is innefficent as depending on how I want the data read it results in arrays with very low sparsity. I was wondering if there was an equivalent way to do this immediately into a full array.
Here's the relevant part of my code
% number of exposures for macro time
frameNos = 0:macroFrames:NFrames;
fBins = uint32(discretize(f,frameNos));
nExps = NFrames/macroFrames;
% generates sparse array Y*X*B x F
bin1 = y+(x-1).*NPixHeight+(b-1).*NPixHeight.*NPixWidth;
bin2 = fBins;
SpCounts = sparse(bin1,bin2,1,NPixHeight*NPixWidth*NBins,nExps);
Generally macroFrames is large so SpCounts is not sparse and therefore very memory inefficient. I imagine appending full() would fix my memory problem but I'm curious if going straight to a full array would be faster?

채택된 답변

Steven Lord
Steven Lord 2023년 8월 3일
It doesn't have exactly the same syntax as the sparse function, but I'd recommend you look at the accumarray function.
  댓글 수: 1
Ife
Ife 2023년 8월 3일
this is exactly what I needed, thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by