Try this:
fs=100; % Sampling frequency (samples per second)
dt = 1/fs; % seconds per sample; the sampling period
t=0:dt:10;
x = 5*sin(2*pi*5*t)+3*cos(2*pi*7*t);
figure(3);
plot(t,x);
xlabel('Time(sec)');
ylabel('x(t)');
title('Signal x(t)');
grid on
[peak_positive,loc_positive] = findpeaks(x); % peaks
[peak_negative,loc_negative] = findpeaks(-x); % valleys
v1 = [peak_positive';-peak_negative']; % positives and negatives in vector form
v2 = [loc_positive';loc_negative'];
peak = [v1 v2];
figure(4);
plot(t,x,'k-');
hold on;
% plot(t(peak(:,2)),peak(:,1),'k*');
plot(t(loc_positive), peak_positive,'k*');
peak_negative = -peak_negative;
plot(t(loc_negative), peak_negative,'ro', 'LineWidth', 2);
hold off
title('Peaks & Valleys of x(t)');
xlabel('Time(sec)');
ylabel('x(t)');
title('Peaks & Valleys of x(t)');
grid on