Does findpeaks work with mat files?

Hi there
I have a very simple question. Does findpeaks work with matfile variables?
I run the following example below and I don't get any errors but my script doesn't detect any peaks. Essentially nothing happens if I run the following.
EPSCs_PYR_1= load('mytrace2131soma&syns.mat', 'mytrace2131syns');
EPSCs_PYR = mytrace2131syns(:,2);
time=mytrace2131syns(:,1);
findpeaks(EPSCs_PYR,time);
What do I do wrong? Similar scripts have worked in the past if I load .dat or .txt files
thank you!

2 Kommentare

Stephen23
Stephen23 am 5 Jul. 2019
Bearbeitet: Stephen23 am 5 Jul. 2019
You load the .mat file into a structure named EPSCs_PYR_1, but you never actually use EPSCs_PYR_1 for anything or refer to it again. Whatever data is imported from that file is ignored by your code.
Hello
that's a good point I will investigate, however it is not entirely true that the variable imported (mytrace2131syns) is ingnored by my code because I can plot this variable just fine using the script below. It is the peak detection that doesn't work on these data.
EPSCs_PYR_1= load('mytrace2131soma&syns.mat', 'mytrace2131syns');
EPSCs_PYR = mytrace2131syns(:,2);
time=mytrace2131syns(:,1);
findpeaks(EPSCs_PYR,time);
plot(time,EPSCs_PYR);

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Stephen23
Stephen23 am 5 Jul. 2019
Bearbeitet: Stephen23 am 5 Jul. 2019

0 Stimmen

Most likely you need to actually refer to the structure that you imported the file data into:
S = load('mytrace2131soma&syns.mat', 'mytrace2131syns');
T = S.mytrace2131syns(:,1);
V = S.mytrace2131syns(:,2);
pks = findpeaks(V,T)

1 Kommentar

Fran
Fran am 5 Jul. 2019
thanks, that looks more correct than what I did previously, however it produces the same output. The script plots my trace but the peakdetection on the trace doesn't work.

Melden Sie sich an, um zu kommentieren.

Star Strider
Star Strider am 5 Jul. 2019

0 Stimmen

... my script doesn't plot my trace and doesn't detect any peaks ...
You are overwriting the findpeaks plot.
Try this instead:
figure
findpeaks(EPSCs_PYR,time);
figure
plot(time,EPSCs_PYR);
Both plots should now appear in their respective figure objects.

8 Kommentare

Fran
Fran am 5 Jul. 2019
Thanks for your reply.
For findpeaks a blank Figure window opens if I follow your suggestion. Plotting my trace works fine as it did from before.
My pleasure.
In the absence of your ‘mytrace2131soma&syns.mat’ file, this will likely remain a mystery.
Nothing I can do to simulate what I believe could be wrong reproduces the problem you report. Even if the argument has no variation at all, findpeaks will produce a plot (if you call it without outputs):
findpeaks(ones(1, 90))
If you give it a cell array or a structure (it only accepts single or double precision vectors), it will throw an error. Since you did not report it throwing any errors, I have no idea what the problem could be.
Fran
Fran am 5 Jul. 2019
Thanks again Star
As a matter of fact my "mytrace2131soma&syns.mat" isn't all that mysterious. Just a voltage trace as a function of time which I can plot without issues. Interestingly running the line you just mentioned: "findpeaks(ones(1, 90))" doesn't generate any plot for me.
I am thinking that this might be a matter of updating my matlab from a 2017 version I am currently using to a 2019.
Star Strider
Star Strider am 5 Jul. 2019
That findpeaks call creates a horizontal line at 1 when I run it (without outputs) in R2019a.
Be sure your MATLAB version has all the latest updates. Click on Add-Ons in the top toolstrip, then scroll down to Check for Updates, then click on Products. I described this procedure in detail in: 2018b Update 3. The problem you’re having with findpeaks could be a bug that was later corrected in your version.
Upgrading to 2019a would definitely be a good idea. (Check for Updates moved to Help in R2019a.)
Fran
Fran am 5 Jul. 2019
awesome thanks so much!
Star Strider
Star Strider am 5 Jul. 2019
My pleasure!
Did you do the updates?
If so, did they solve your problem?
Fran
Fran am 6 Jul. 2019
Bearbeitet: Fran am 6 Jul. 2019
I installed R2019a but our administator hasn't send me the licenses to update my matlab server yet, thus the R2019a is too new for my existing license files. I am now installing R2018b for the next month or so, at least until I update the server. I will let you know how it goes!
PS: in terms of updates, following your instructions everything appeared to be up-to-date in my previous 2017 version.
Star Strider
Star Strider am 6 Jul. 2019
Please do!
I have no idea what the problem with findpeaks is in your R2017 installation. I never had any problems with it.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 5 Jul. 2019

Kommentiert:

am 6 Jul. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by