Error in defining x values for peak analysis in Matlab

1 view (last 30 days)
Hi. I have a problem in creating plot for peak analysis. It can plot the data but not for the x-axis. My data is in the form of double, and my x-axis is datetime. However, when I plot findpeaks, I got an error warning :
"Error using findpeaks
Expected X to be increasing valued.
Error in findpeaks>parse_inputs (line 242)
validateattributes(seconds(Xin-Xin(1)),{'double'},{'real','finite','vector','increasing'},'findpeaks','X');
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});"
The value of my datetime data actually increase by the number of rows, so I wonder why I got an error. I attach the picture of my datetime data. Could you please help me? I have been working on this problem since morning and up to know I got nothing :(. Thank you for your help.
  1 Comment
Ganavi Mg
Ganavi Mg on 7 Feb 2018
Hi Even I got same error as you got. My code is clc; clear all; load('DATA_01_TYPE01.mat'); [n, p] = size(sig); t=1:n; plot((1:1000),sig(2,1:1000)); xlabel('samples') ylabel('sample amplitude') title('User1') figure; n=1000; ts =0.0001; ws = 2*pi/ts; f = fft(sig(2,1:1000)); w = ws*(-n/2:(n/2)-1)/n; plot(w,abs(f)) xlabel('frequency'); ylabel('amplitude'); title('fast fourier transform of PPG DATA'); [pks,locs]= findpeaks(frequency,sample amplitude); In the place of frequency,sample amplitude what value we must use. I need peak analysis of signal. The data is in .mat format. I had loaded the mat values in to my code, then found out the fft of the data. I need peak of the signals. What I should do now ?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Oct 2017
I suspect you are using R2015b or earlier; datetime was not permitted for the "location" parameter until R2016a.
  7 Comments
Walter Roberson
Walter Roberson on 24 Oct 2017
You do not need most of that.
t = finalCSVnew{:,1};
tisdup = [false; diff(t(:)) == 0];
finalCSVnew(tisdup, :) = [];
Kasih Ditaningtyas Sari Pratiwi
Awesome! Thank you so much Walter! You're really smart! Hopefully when later I am no longer a newbie in matlab programming, I can answer the question as you do. Thank you again :D

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!