%hScanLTEWaveformDataTip implements data tips on reference signal
%measurement plot
%   hScanLTEWaveformDataTip displays the OUTTEXT on the plot, which has
%   cell information and its corresponding frequency based on the position
%   of user's click.
%   EVENTOBJ - User's click information
%   CELLIDS - Detected cell IDs
%   RSM - Reference signal measurements
%   FREQ - Frequency of detected cells
%   NUMOFCELLFREQ - Cell count at each detected frequency

%   Copyright 2019 The MathWorks, Inc.

function outText = hScanLTEWaveformDataTip...
    (~,eventObj,cellIds,rsm,Freq,numOfCellFreq)
    pos = get(eventObj,'Position');
    idx = find(pos(1) == Freq,1);
    if any(Freq == pos(1))
        idx1 = 3*(idx-1);
        cellfrequencyRSMIndices = ((1+idx1:(idx1+numOfCellFreq(idx))));
        cellIndex = find(abs(rsm(cellfrequencyRSMIndices)-pos(2))<1e-3);
        idx2 = sum(numOfCellFreq(1:idx-1));
        outText = {['Frequency: ',num2str(pos(1)),' MHz'], ...
            ['Cell ID: ',num2str(cellIds(idx2+cellIndex))]};
    else
        outText = {['Frequency: ',num2str(pos(1)),' MHz'], 'No cell found'};
    end
end