Incompatible Indices when updating matrix in the loop
Show older comments
Hey everyone!
I am doing some ECG analysis. I am trying to create a 2D-array that is updated for every loop iteration, but I get the following error when I run the code "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side." Any idea on how to fix it?
Note: I know it is bad practice to not preallocate memory for matrices, but I am dealing with very large amounts of data and I cannot find its size.
%% Frequency Domain Analysis
fs3 = 4; % 4 hertz sampling frequency
xdft = [];
PowerSpectralDensity = [];
for i = 0: 60: (60-1)*240
starttime2 = i;
finishtime2 = starttime2 + 60;
StartElement2 = starttime2 *fs+1;
FinishElement2 = finishtime2 * fs;
minuteSubset2 = ECG (StartElement2 : FinishElement2);
t3 = starttime2: 1/fs3: finishtime2 - 1/fs3;
%resampling the data to frequency = 4
minuteSubset2_rs = resample(minuteSubset2, fs3, fs);
N = length(minuteSubset2_rs);
xdft = fft(minuteSubset2_rs');
PowerSpectralDensity = (1/(fs3*N))* abs(xdft).^2;
PowerSpectralDensity = PowerSpectralDensity(1:N/2);
for j = 1: 240
PDarray(i/60 +1, j) = xdft; %error in this line
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!