private void AppendSample(ECGFrame[] samples, int length) { var sampleForSize = samples.First(); double[,] unFilteredData = new double[length * sampleForSize.FrameData.First().Count, sampleForSize.FrameData.Count]; double[,] filteredData = new double[length * sampleForSize.FilteredFrameData.First().Count, sampleForSize.FilteredFrameData.Count]; long[,] timestampData = new long[length * sampleForSize.FilteredFrameData.First().Count, 1]; ulong[,] packetIdData = samples[0].PacketId == UInt64.MaxValue ? null : new ulong[length, 1]; ulong[,] kalpaClockData = samples[0].KalpaClock == UInt64.MaxValue ? null : new ulong[length, 1]; for (var i = 0; i < length; i++) { var dataSample = samples[i]; var rows = dataSample.FrameData.First().Count; var columns = dataSample.FrameData.Count; for (int rowIndex = 0; rowIndex < rows; rowIndex++) { for (var columnIndex = 0; columnIndex < columns; columnIndex++) { unFilteredData[i * rows + rowIndex, columnIndex] = dataSample.FrameData[columnIndex][rowIndex]; } } rows = dataSample.FilteredFrameData.First().Count; columns = dataSample.FilteredFrameData.Count; for (int rowIndex = 0; rowIndex < rows; rowIndex++) { for (var columnIndex = 0; columnIndex < columns; columnIndex++) { filteredData[i * rows + rowIndex, columnIndex] = dataSample.FilteredFrameData[columnIndex][rowIndex]; } } int rowsTimestamps = dataSample.FilteredFrameData.First().Count; for (int k = 0; k < rowsTimestamps; k++) { var date = dataSample.Timestamp; if (SamplingRate > 0) { date = (long)(dataSample.Timestamp + k * 1000.0 / SamplingRate); } timestampData[i * rowsTimestamps + k, 0] = date; EndDateTime = date; } if (packetIdData != null) { packetIdData[i, 0] = dataSample.PacketId; } if (kalpaClockData != null) { kalpaClockData[i, 0] = dataSample.KalpaClock; } } UnFiltered.AppendOrCreateDataset(unFilteredData); Filtered.AppendOrCreateDataset(filteredData); Timestamps.AppendOrCreateDataset(timestampData); if (packetIdData != null) { PacketIds.AppendOrCreateDataset(packetIdData); } }