Hi @MH,
As an example, I took few data points extracted from your attached example excel to achieve your goal which was to extract the load values corresponding to the nearest achieved angles for each actuator, allowing for a normalized comparison of the data when plotted. To let you know the data is structured in a MATLAB cell array, and I implemented a solution to find the nearest achieved angle for each setpoint and export the corresponding load values. Please see example code below.
% Define the data data = { 'Setpoint_Angle', 'Compu1_Angle', 'Compu1_Load', 'Compu2_Angle', 'Compu2_Load', ... 'Angle from -50 to 10', 'Increment', 'Angles to Plot', ... 'Compu1_Load_Equivalent_to_Nearest_Achieved_Angle', 'Compu2_Load_Equivalent_to_Nearest_Achieved_Angle'; -50, -50.8393985, 27.4088035, -48.5664535, 10.37836, [], 0.1, -50, [], []; -50, -50.822903, 26.439119, -48.5691845, 10.642191, [], [], -49.9, [], []; -50, -50.834693, 26.200912, -48.559871, 10.809034, [], [], -49.8, [], []; -50, -50.8604875, 27.065817, -48.5350735, 10.7726315, [], [], -49.7, [], []; -50, -50.860664, 27.056357, -48.539529, 11.0753485, [], [], -49.6, [], []; -50, -50.8673415, 27.0642945, -48.539529, 11.0733345, [], [], -49.5, [], []; -50, -50.8673415, 27.656562, -48.5337885, 10.9056425, [], [], -49.4, [], []; -50, -50.9265905, 27.6753015, -48.5337885, 10.6345015, [], [], -49.3, [], []; };
% Extract angles and loads setpoint_angles = data(2:end, 1); compu1_angles = data(2:end, 2); compu1_loads = data(2:end, 3); compu2_angles = data(2:end, 4); compu2_loads = data(2:end, 5);
% Initialize arrays for nearest loads nearest_compu1_loads = zeros(length(setpoint_angles), 1); nearest_compu2_loads = zeros(length(setpoint_angles), 1);
% Loop through each setpoint angle to find the nearest achieved angle for i = 1:length(setpoint_angles) setpoint = setpoint_angles{i};
% Find the nearest angle for Compu1 [~, idx1] = min(abs(cell2mat(compu1_angles) - setpoint)); nearest_compu1_loads(i) = compu1_loads{idx1};
% Find the nearest angle for Compu2 [~, idx2] = min(abs(cell2mat(compu2_angles) - setpoint)); nearest_compu2_loads(i) = compu2_loads{idx2}; end
% Update the data array with the nearest loads data(2:end, 9) = num2cell(nearest_compu1_loads); data(2:end, 10) = num2cell(nearest_compu2_loads);
% Display the updated data disp(data);
So,as you can see in the code, the data is defined in a cell array, where each row corresponds to a set of measurements for the actuators at specific angles.The code extracts the setpoint angles, achieved angles, and load values for both actuators into separate variables for easier manipulation. Afterwards, two arrays, nearest_compu1_loads and nearest_compu2_loads, are initialized to store the load values corresponding to the nearest achieved angles for each setpoint. Then, a loop iterates through each setpoint angle. The min function is used to find the index of the nearest achieved angle for Compu1 and Compu2 by calculating the absolute difference between the setpoint and the achieved angles.The corresponding load values are then stored in the initialized arrays.The nearest load values are updated in the original data array, specifically in the columns designated for the equivalent loads.Finally, the updated data array is displayed, showing the setpoint angles alongside their corresponding nearest load values for both actuators.
Please see attached.
Hope this answers your question and help you get started with your project.