%% Set Label Value
% Load a labeled signal set containing recordings of whale songs.

load whales
lss

%
% Add a new label to the signal set, corresponding to the maximum value of each member.

theMax = signalLabelDefinition('Maximum', ...
    'LabelDataType','numeric', ...
    'Description','Maximum value of the signal');
addLabelDefinitions(lss,theMax)

%
% For each labeled signal, set the value of the new label to the signal maximum. Plot the signals and their maxima.

fs = lss.SampleRate;
for k = 1:lss.NumMembers
    sg = getSignal(lss,k);
    [mx,ix] = max(sg);
    
    setLabelValue(lss,k,'Maximum',mx)
    
    subplot(2,1,k)
    plot((0:length(sg)-1)/fs,sg,ix/fs,mx,'*')
end

%
% Display the names and values of the labels in the set.

lbldefs = getLabelValues(lss)

% Decide that the signal maximum is better represented as a point label than as an attribute. Remove the numeric definition and redefine the maximum.

removeLabelDefinition(lss,'Maximum')
theMax = signalLabelDefinition('Maximum', ...
    'LabelType','point','LabelDataType','numeric', ...
    'Description','Maximum value of the signal');
addLabelDefinitions(lss,theMax)

% For each labeled signal, set the value of the new label to the signal maximum.

for k = 1:lss.NumMembers
    sg = getSignal(lss,k);
    [mx,ix] = max(sg);
    setLabelValue(lss,k,'Maximum',ix/fs,mx)
end

% Plot the signals and their maxima.

for k = 1:lss.NumMembers
    subplot(2,1,k)
    sg = getSignal(lss,k);
    peaks = getLabelValues(lss,k,'Maximum');
    plot((0:length(sg)-1)/fs,sg, ...
        peaks.Location,cell2mat(peaks.Value),'*')
end

%
% Copyright 2018 The MathWorks, Inc.