Suppose I have data in a table rawData
:
ColA | ColB | ColC |
---|---|---|
137.326 | -92.699 | 185.085 |
137.764 | -91.964 | 185.400 |
138.189 | -91.224 | 185.670 |
138.382 | -90.140 | 185.985 |
... | ... | ... |
I need to resample the data based on ColC
at intervals of 0.1 and have the values in the other columns interpolated accordingly.
I've tried using resample
in various invocations, but all I get are error messages that I don't understand. (Matlab is new to me.)
The documentation has an example for non-uniform data, but I can't seem to make it work.
Any suggestions?
In the end, I found a solution that works for what I need. I'm not sure if there's a better way, but this is what I came up with.
% move ColC to front
rawData = movevars(rawData, "ColC", "Before", "ColA");
% convert table to a matrix
rawDataMat = table2array(rawData);
% create desired resampling interval
inc = 0:0.1:360;
% initialize resampled matrix from interval
resampled = inc';
% resample each additional column
resampled(:,2) = interp1(rawDataMat(:,1),rawDataMat(:,2),inc);
resampled(:,3) = interp1(rawDataMat(:,1),rawDataMat(:,3),inc);
% convert back to a table
resampledTbl = array2table(resampled);
% rename table vars
resampledTbl.Properties.VariableNames(1) = "ColC";
resampledTbl.Properties.VariableNames(2) = "ColA";
resampledTbl.Properties.VariableNames(3) = "ColB";