MATLAB: How to use findpeaks for every column of a matrix and store the result in a cell array

cell arrayecgfind peakfor looppeakssignal processingstorage

I am trying to run this code:
for i=1:numel(locs1)
peak_1q{i}=findpeaks(Qxy(:,numel(locs1)));
end;
I am getting this error:
Cell contents assignment to a non-cell array object.
Error in T_5Dec4 (line 52)
peak_1q{i}=findpeaks(Qxy(:,numel(locs1)))
I need to store the value in a cell array,each column may have more than 1 peak .If I store it in a matrix (preallocated before the for loop,I get only the peaks for the last iteration of the loop. if I use
peak_1q(i)=findpeaks(Qxy(:,numel(locs1)))
I get this error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in T_5Dec4 (line 53)
peak_1q(i)=findpeaks(Qxy(:,numel(locs1)))
Any suggestions? How do I find and store the peaks from each column of the given data?

Best Answer

Preallocate it as a cell array:
peak_1q = cell(1,numel(locs1));
If you do not preallocate then apparently you have some already-existing non-cell variable in the workspace, and MATLAB will try to use that.