MATLAB: Can you find peaks and their locations of multiple frames at once

export peaks and locationsfind peaksfind peaks of multiple spectra

Hi all, I know that [pks,locs] will export the found peaks and their locations into the workspace. We have 120 frames of spectra, all of which need this operation. I have not been able to find a way to perform [pks,locs] to all of the 120 frames simultaneously. Is there a for loop or any other way to program this so that Matlab will export the peaks and locations, with a specific name for each frame, all at once?
Thanks!

Best Answer

for FrameNo = 1 : 120
[pks{FrameNo}, locs{FrameNo}] = findpeaks(YourArray(:,:,:,FrameNo));
end
Adjust as appropriate for how many dimensions you have in your array.
If you have the Parallel Computing Toolbox, then you can parpool() and change the "for" to "parfor".