Display all the intermediate results of a code

5 views (last 30 days)
Dear MatLab users,
As beginner of MatLab, I am facing an issue that I cannot solve alone. I am using "findpeaks" as code to extract the number of peaks and the corresponding width (halfheight) of a data array. The code (very simple) is the following:
importdata('...\data.dat');
x=ans(:,1);
for i=[2:47]
[pks,locs,widths,proms] = findpeaks(ans(:,i),x,'MinPeakProminence',40,'Annotate','extents','WidthReference','halfheight');
widths
end
However the code only stores the last result (width), while I would like that the code stored all the results for each y coordinate, that is 'ans(:,i)'.
Any advise would be really helpful.
Thanks.
Paolo

Accepted Answer

Paolo Costa
Paolo Costa on 12 Nov 2019
Dear Walter,
thanks for your quick reply.
Unfortunately, the code does not work by showing the following message:
Unable to perform assignment because brace indexing is not supported for variables of this type.
Error in Peaks_TimeTrace_TIRF_new (line 3)
[pks{i},locs{i},widths{i},proms{i}] =
findpeaks(data(:,i+1),x,'MinPeakProminence',40,'Annotate','extents','WidthReference','halfheight ');
Thanks.
Paolo
  2 Comments
Walter Roberson
Walter Roberson on 12 Nov 2019
You did not clear your variables and you are not using a function, so you have numeric pks or locs or widths or proms variables hanging around in your workspace.
clear pks locs widths proms

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 12 Nov 2019
data = ans;
for i=1:46
[pks{i},locs{i},widths{i},proms{i}] = findpeaks(data(:,i+1),x,'MinPeakProminence',40,'Annotate','extents','WidthReference','halfheight');
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!