Multiply tall array with array

조회 수: 5 (최근 30일)
Ervin
Ervin 2024년 4월 25일
답변: Edric Ellis 2024년 4월 29일
I have a tall array, that contains audio samples created from a dataset like this:
dataS = tall(fileDatastore(fullfile(appData.OutputDirectoryPath, 'tmp_*.mat'), ...
'ReadFcn', @(fname) getfield(load(fname), 'resampled'), ...
'UniformRead', true));
This data is large, but its element count is known. I need to multiply this data with a signal:
t = ((0:N-1)'/fsn);
carrier = exp(1j*2*pi*carrierFreq*t);
ccy = dataS.*carrier;
The last line fails, with the following error:
Error using .*
Incompatible non-scalar tall array arguments. Each of the tall arrays must be the same size in the first dimension, must be derived from a single tall array, and must not have been indexed differently in the first
dimension (indexing operations include functions such as VERTCAT, SPLITAPPLY, SORT, CELL2MAT, SYNCHRONIZE, RETIME and so on).
I assume the issue is that it cannot guarantee that the arrays are compatible, but I can guarantee it. How can I do it?
  댓글 수: 2
the cyclist
the cyclist 2024년 4월 25일
Have you verified that the two arrays are the same size? Try putting this in your code, prior to that calculation:
size(dataS)
size(carrier)
Ervin
Ervin 2024년 4월 25일
Yes, I have, but I actually need to use:
gather(size(dataS))

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

답변 (1개)

Edric Ellis
Edric Ellis 2024년 4월 29일
You need to use a bit of a trick to construct the colon vector. (This trick is alluded to on this doc page). Basically, you need to use find together with an element-wise expression derived from dataS such that the value of the expression is always true. This causes find to return 1:N in such a form that it can be combined with dataS. Like this:
dataS = tall(rand(1000,1));
% Use a trick to generate 1:(height(dataS))
cvec = find(true | isnan(dataS));
% Now, continue to compute t
fsn = 0.1;
t = (cvec-1) / fsn;
carrierFreq = 1000;
carrier = exp(1j*2*pi*carrierFreq*t);
gather(head(dataS .* carrier))
Evaluating tall expression using the Local MATLAB Session: - Pass 1 of 2: 0% complete - Pass 1 of 2: Completed in 0.26 sec - Pass 2 of 2: 0% complete - Pass 2 of 2: Completed in 0.18 sec Evaluation completed in 0.85 sec
ans =
0.7841 + 0.0000i 0.0410 - 0.0000i 0.9299 - 0.0000i 0.8883 - 0.0000i 0.5102 - 0.0000i 0.1375 - 0.0000i 0.5657 - 0.0000i 0.9033 - 0.0000i

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by