Auswertung Experiment
Database tüddelei DBHanlder läuft gut für DIESE Datanbank struktur... App begonnen aber weit entfernt von gutem Stand
This commit is contained in:
139
Functions/Lab_helper/showCurrentMeasurement.m
Normal file
139
Functions/Lab_helper/showCurrentMeasurement.m
Normal file
@@ -0,0 +1,139 @@
|
||||
function showCurrentMeasurement(varargin)
|
||||
|
||||
% USEFUL FOR LAB!
|
||||
|
||||
% showCurrentMeasurement displays lab measurement data in a table figure with variable names
|
||||
% as column headers and values listed below. Calling the function multiple times
|
||||
% with the same variable names but different values adds more data points.
|
||||
%
|
||||
% Usage:
|
||||
% showCurrentMeasurement('VariableName1', VariableValue1, 'VariableName2', VariableValue2, ...)
|
||||
%
|
||||
% Example:
|
||||
% % First measurement
|
||||
% voltage = 5.12;
|
||||
% ber = 3.86e-5;
|
||||
% power = voltage * 0.85;
|
||||
% showCurrentMeasurement('Voltage', voltage, 'ber', ber, 'Power', power);
|
||||
%
|
||||
% % Second measurement
|
||||
% voltage = 5.15;
|
||||
% ber = 2.54e-5;
|
||||
% power = voltage * 0.90;
|
||||
% showCurrentMeasurement('Voltage', voltage, 'ber', ber, 'Power', power);
|
||||
|
||||
% Validate that inputs are in name-value pairs
|
||||
if mod(nargin, 2) ~= 0
|
||||
error('Inputs must be provided as name-value pairs.');
|
||||
end
|
||||
|
||||
% Extract variable names and values
|
||||
numPairs = nargin / 2;
|
||||
names = varargin(1:2:end);
|
||||
values = varargin(2:2:end);
|
||||
|
||||
% Ensure variable names are strings
|
||||
for i = 1:length(names)
|
||||
if ~ischar(names{i}) && ~isstring(names{i})
|
||||
error('Variable names must be strings.');
|
||||
end
|
||||
names{i} = char(names{i});
|
||||
end
|
||||
|
||||
% Convert values to strings for display
|
||||
for i = 1:length(values)
|
||||
varNameLower = names{i}; % Convert variable name to lowercase for case-insensitive comparison
|
||||
if isnumeric(values{i})
|
||||
if any(contains(varNameLower, {'ber','mlse','ffe','db'},"IgnoreCase",true))
|
||||
% Format 'ber' values in exponential notation with two decimal places
|
||||
values{i} = sprintf('%.2e', values{i});
|
||||
else
|
||||
values{i} = num2str(values{i});
|
||||
end
|
||||
else
|
||||
values{i} = char(values{i});
|
||||
end
|
||||
end
|
||||
|
||||
% Define a unique tag for the figure to locate it later
|
||||
figTag = 'CurrentMeasurementsFigure';
|
||||
|
||||
% Try to find an existing figure with the specified tag
|
||||
hFig = findobj('Type', 'figure', 'Tag', figTag);
|
||||
|
||||
if isempty(hFig)
|
||||
% Create a new figure and table
|
||||
hFig = figure('Name', 'Current Measurements', 'NumberTitle', 'off', ...
|
||||
'MenuBar', 'none', 'ToolBar', 'none', 'Resize', 'on', ...
|
||||
'Tag', figTag);
|
||||
|
||||
% Initialize data and column names
|
||||
data = values;
|
||||
columnNames = names;
|
||||
|
||||
% Create the uitable
|
||||
hTable = uitable('Parent', hFig, 'Data', data, ...
|
||||
'ColumnName', columnNames, ...
|
||||
'FontSize', 14, ...
|
||||
'RowName', [], ...
|
||||
'Units', 'normalized', ...
|
||||
'Position', [0, 0, 1, 1]);
|
||||
% Adjust column widths
|
||||
setColumnWidths(hTable);
|
||||
|
||||
% Store the table handle for future use
|
||||
setappdata(hFig, 'DataTable', hTable);
|
||||
else
|
||||
% Retrieve the existing table handle
|
||||
hTable = getappdata(hFig, 'DataTable');
|
||||
|
||||
% Get current data and column names
|
||||
currentData = get(hTable, 'Data');
|
||||
columnNames = get(hTable, 'ColumnName');
|
||||
|
||||
% Ensure that variable names are consistent
|
||||
if ~isequal(columnNames, names')
|
||||
error('Variable names must be consistent with previous calls.');
|
||||
end
|
||||
|
||||
% Append new data to the existing data
|
||||
updatedData = [currentData; values];
|
||||
|
||||
% Update the table data
|
||||
set(hTable, 'Data', updatedData);
|
||||
|
||||
% Adjust column widths
|
||||
setColumnWidths(hTable);
|
||||
end
|
||||
|
||||
% Adjust the figure size to fit the table content without changing its position
|
||||
drawnow;
|
||||
tableExtent = get(hTable, 'Extent');
|
||||
% Get the current figure position
|
||||
figPosition = get(hFig, 'Position');
|
||||
% Update the figure size while preserving the position
|
||||
figPosition(3) = max(figPosition(3), tableExtent(3) + 20); % Width
|
||||
figPosition(4) = max(figPosition(4), tableExtent(4) + 20); % Height
|
||||
set(hFig, 'Position', figPosition);
|
||||
end
|
||||
|
||||
function setColumnWidths(hTable)
|
||||
% Helper function to adjust column widths based on content
|
||||
data = get(hTable, 'Data');
|
||||
columnNames = get(hTable, 'ColumnName');
|
||||
numColumns = length(columnNames);
|
||||
columnWidths = cell(1, numColumns);
|
||||
|
||||
% Calculate the maximum width needed for each column
|
||||
for col = 1:numColumns
|
||||
maxContentLength = max(cellfun(@length, data(:, col)));
|
||||
headerLength = length(columnNames{col});
|
||||
maxLength = max(maxContentLength, headerLength);
|
||||
|
||||
% Estimate pixel width (approximate, adjust as needed)
|
||||
pixelWidth = maxLength * 14; % 8 pixels per character as an estimate
|
||||
columnWidths{col} = pixelWidth;
|
||||
end
|
||||
|
||||
set(hTable, 'ColumnWidth', columnWidths);
|
||||
end
|
||||
Reference in New Issue
Block a user