Untitled
function LogarithmicDecrementGUI % Create the GUI fig = uifigure('Name', 'Logarithmic Decrement Analysis', 'Position', [100, 100, 600, 400]); % Load Data Button uibutton(fig, 'Text', 'Load Data', ... 'Position', [20, 350, 100, 30], ... 'ButtonPushedFcn', @(~,~) loadData(fig)); % Input for Xo uilabel(fig, 'Text', 'Xo:', 'Position', [20, 300, 30, 30]); XoInput = uieditfield(fig, 'numeric', 'Position', [50, 300, 100, 30]); % Input for Xn uilabel(fig, 'Text', 'Xn:', 'Position', [20, 250, 30, 30]); XnInput = uieditfield(fig, 'numeric', 'Position', [50, 250, 100, 30]); % Input for n uilabel(fig, 'Text', 'n:', 'Position', [20, 200, 30, 30]); nInput = uieditfield(fig, 'numeric', 'Position', [50, 200, 100, 30]); % Calculate Button uibutton(fig, 'Text', 'Calculate', ... 'Position', [20, 150, 100, 30], ... 'ButtonPushedFcn', @(~,~) calculateDecrement(XoInput, XnInput, nInput)); % Axes for plotting ax1 = uiaxes(fig, 'Position', [200, 200, 350, 150], 'Title', 'Acceleration vs. Time'); ax2 = uiaxes(fig, 'Position', [200, 20, 350, 150], 'Title', 'Logarithmic Decrement vs. Cycle Number'); % Store axes in the figure's UserData for access in callback functions fig.UserData.ax1 = ax1; fig.UserData.ax2 = ax2; end % Callback to Load Data and Plot Acceleration vs. Time function loadData(fig) [file, path] = uigetfile('*.xlsx', 'Select Excel File'); if isequal(file, 0) return; % User canceled end filename = fullfile(path, file); data = readtable(filename); % Adjust column names based on the user data time = data.Time; % Replace with the actual name of your time column abs_accel = data.AbsoluteAcceleration; % Replace with your absolute acceleration column name % Plot acceleration vs. time ax1 = fig.UserData.ax1; plot(ax1, time, abs_accel, '-b', 'LineWidth', 1.5); xlabel(ax1, 'Time (s)'); ylabel(ax1, 'Absolute Acceleration (m/s^2)'); title(ax1, 'Acceleration vs. Time'); grid(ax1, 'on'); % Find peaks and plot logarithmic decrement graph [peaks, peak_times] = findpeaks(abs_accel, time); ax2 = fig.UserData.ax2; num_cycles = length(peaks) - 1; log_dec = zeros(num_cycles, 1); for i = 1:num_cycles log_dec(i) = log(peaks(i) / peaks(i+1)); end % Plot logarithmic decrement cycle_numbers = 1:num_cycles; plot(ax2, cycle_numbers, log_dec, '-k', 'LineWidth', 1.5); xlabel(ax2, 'Cycle Number'); ylabel(ax2, 'Logarithmic Decrement (\delta)'); title(ax2, 'Logarithmic Decrement vs. Cycle Number'); grid(ax2, 'on'); % Store data in the figure for future use fig.UserData.peaks = peaks; fig.UserData.peak_times = peak_times; fig.UserData.log_dec = log_dec; end % Callback to Calculate Decrement Based on Xo, Xn, and n function calculateDecrement(XoInput, XnInput, nInput) Xo = XoInput.Value; Xn = XnInput.Value; n = nInput.Value; if isempty(Xo) || isempty(Xn) || isempty(n) uialert(XoInput.Parent, 'Please enter all values (Xo, Xn, and n).', 'Input Error'); return; end delta = (1 / n) * log(Xo / Xn); % Logarithmic decrement calculation uialert(XoInput.Parent, sprintf('Logarithmic Decrement: %.4f', delta), 'Result'); end
Leave a Comment