Clear Filters
Clear Filters

Linking two sets of data to be in line with eachother

1 view (last 30 days)
Hey, I have two tables, each with a column for load and position. I'm hoping to use one set of load data, to search the other table for the nearest load value and extract it's relative position. I would then subtract that position from the original tables position (likely into a new array).
I believe this should be done with indexing, but I'm pretty confused on the subject (especially considering the load values aren't exactly equal, I just need to index to the cloest value)
Any tips would be helpful!

Accepted Answer

Cameron Hudspith
Cameron Hudspith on 16 Oct 2023
The following function is the solution to my problem. I was able to put it into a loop to apply the result to every row of my dataset. Thanks to everyone who helped.
[~,idx] = min(abs(PressingPlate_FP{:,"LoadN"}-Control_FP{i,"LoadN"}));
result = PressingPlate_FP{idx, "Positionmm"};

More Answers (1)

Walter Roberson
Walter Roberson on 15 Oct 2023
Perhaps
idx = interp1(loadValues1, 1:numel(loadValues1), loadValues2, 'nearest')
  1 Comment
Cameron Hudspith
Cameron Hudspith on 16 Oct 2023
I believe that is on the right track, but I can't get the function to work
i=1;
idx = interp1(PressingPlate_FP(:,"LoadN"), PressingPlate_FP(:,"Positionmm"), Control_FP{i,"LoadN"}, 'nearest');
In that code I'm hoping interp1 will search the load column of the PressingPlate_FP table for the nearest value to Control_FP{i,"LoadN"}, then return The value of the position column of PressingPlate_FP directly next to the load value
The function is currently giving me an error

Sign in to comment.

Tags

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!