Multiply tall array with array
3 次查看(过去 30 天)
显示 更早的评论
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
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)
回答(1 个)
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))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!