Incompatible Indices when updating matrix in the loop
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
William Rose
2021-12-15
On the line in question, you are assigning vector xdft (right hand side) to one element of array PDarray(). That won't work. You must assign a vector to a row or column of an array, and the sizes must match.
Please provide values for fs and array ECG(), if you want others to be able to run this code.
4 个评论
William Rose
2021-12-16
@Mouath Abu-Daoud, I'm glad that my answer was helpful. Good luck with your work!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!