Multiply tall array with array

3 Ansichten (letzte 30 Tage)
Ervin
Ervin am 25 Apr. 2024
Beantwortet: Edric Ellis am 29 Apr. 2024
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 Kommentare
the cyclist
the cyclist am 25 Apr. 2024
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 am 25 Apr. 2024
Yes, I have, but I actually need to use:
gather(size(dataS))

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Edric Ellis
Edric Ellis am 29 Apr. 2024
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

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by