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:
48
Functions/Lab_helper/holdAndShowValue.m
Normal file
48
Functions/Lab_helper/holdAndShowValue.m
Normal file
@@ -0,0 +1,48 @@
|
||||
function holdAndShowValue()
|
||||
% Create the UI figure
|
||||
fig = uifigure('Name', 'Multi-Channel Power Monitor', 'Position', [100 100 600 150]);
|
||||
|
||||
% Create labels to display the power values for each channel in a horizontal layout
|
||||
powerLabels = gobjects(4, 1);
|
||||
for i = 1:4
|
||||
powerLabels(i) = uilabel(fig, 'Position', [50 + (i-1)*130, 70, 120, 30], ...
|
||||
'FontSize', 18, 'HorizontalAlignment', 'center');
|
||||
powerLabels(i).Text = sprintf('CH %d: Fetching...', i);
|
||||
end
|
||||
|
||||
% Create the "OK" button
|
||||
okButton = uibutton(fig, 'push', 'Text', 'OK', 'Position', [250 20 100 40], ...
|
||||
'ButtonPushedFcn', @(src, event) closeWindow());
|
||||
|
||||
% Initialize the timer
|
||||
updateTimer = timer('ExecutionMode', 'fixedRate', 'Period', 1, ...
|
||||
'TimerFcn', @(src, event) updatePowerValues());
|
||||
|
||||
% Start the timer
|
||||
start(updateTimer);
|
||||
|
||||
% Function to close the window and stop the timer
|
||||
function closeWindow()
|
||||
stop(updateTimer);
|
||||
delete(updateTimer);
|
||||
delete(fig);
|
||||
end
|
||||
|
||||
% Function to fetch and update power values for all channels
|
||||
function updatePowerValues()
|
||||
powerValues = fetchPowerValues(); % Replace with your data-fetching function
|
||||
for i = 1:4
|
||||
powerLabels(i).Text = sprintf('CH %d: %.2f dBm', i, powerValues(i));
|
||||
end
|
||||
end
|
||||
|
||||
% Wait until the figure is closed to resume execution
|
||||
waitfor(fig);
|
||||
end
|
||||
|
||||
% Example function to simulate fetching power values for four channels
|
||||
function powerValues = fetchPowerValues()
|
||||
% Replace this with actual code to get the power values from the power meter
|
||||
[p1,p2,p3,p4] = OptAtten().readPower();
|
||||
powerValues = [p1,p2,p3,p4];
|
||||
end
|
||||
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
|
||||
20
Functions/Lab_helper/waitUntilClick.m
Normal file
20
Functions/Lab_helper/waitUntilClick.m
Normal file
@@ -0,0 +1,20 @@
|
||||
function waitUntilClick()
|
||||
% Create the UI figure
|
||||
fig = uifigure('Name', 'Pause Execution', 'Position', [100 100 300 150]);
|
||||
|
||||
% Create a label to inform the user
|
||||
uilabel(fig, 'Position', [50 80 200 40], 'Text', 'Click "Continue" to proceed', ...
|
||||
'FontSize', 14, 'HorizontalAlignment', 'center');
|
||||
|
||||
% Create the "Continue" button
|
||||
continueButton = uibutton(fig, 'push', 'Text', 'Continue', 'Position', [100 20 100 40], ...
|
||||
'ButtonPushedFcn', @(src, event) closeWindow());
|
||||
|
||||
% Function to close the window when "Continue" is clicked
|
||||
function closeWindow()
|
||||
delete(fig); % Close the figure window
|
||||
end
|
||||
|
||||
% Wait until the figure is closed to resume execution
|
||||
waitfor(fig);
|
||||
end
|
||||
Reference in New Issue
Block a user