Hi everyone,
I have this code for my spectrum:
[spectrum2,locations] = findpeaks(spectrum,5e5);
locations = locations * 5e5;
spectrum3 = rand(length(spectrum),1);
for i = 1:length(spectrum)
for j = 1:length(locations)
if i == locations(j)
spectrum3(i) = spectrum(i);
else
spectrum3(i) = 0;
end
end
end
The size of my spectrum array is 50 million, but after using findpeaks and plotting the array size is collapsed to around 3000. I would like the array elements to be 0 unless they correspond to the location of a peak, in which instance I would like the element to be the value it was originally. I've tried using these loops to do that but the array comes out as a flat line - how do I achieve what I'm trying to do? Is there a simpler way?
Thanks!
Tom