Question
Hi, I am trying to use findpeaks over a matrix, x, column by column. I am using a for loop as below: for k=1:size(x,2) [P{k},locs{k},widths,proms{k}]=findpeaks(x(:,k)) end Everything is working fine except for returning widths. P, locs and proms all return as cell arrays with all the data for the peaks in each column. However, widths only returns the widths of the peaks for the last column. When I try to edit it by making widths return as a cell array: for k=1:size(x,2) [P{k},locs{k},widths{k},proms{k}]=findpeaks(x(:,k)) end I get the error message "Cell contents assignment to a non-cell array object" Is there a way to get this function to return all the widths of all the peaks for each column?
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 24, 2026
Hi,
I tried with the Release R2017b that is mentioned in question and with the latest Release that is R2019b but didn’t find any issues while running the code. Still I guess you may try pre declare the variables that are returned from findpeaks as below.
P = cell(1,size(deltaFoFCopy,2)); locs = cell(1,size(deltaFoFCopy,2)); widths = cell(1,size(deltaFoFCopy,2)); proms = cell(1,size(deltaFoFCopy,2));
Also, from the data file I can see that some columns are entirely zero so for those only empty vectors will return. Therefore, for some indexes in cell array the value will be empty vectors.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →