Hello, I have a structure array which consists of 39 variables (LFHD, RFHD, etc.) Each of those variables contains 3 double arrays of size 1 x ?. I would like to interpolate those double arrays from 1 x ? to 1 x 101 (0-100%) so that they are all the same length and I can average across them.
I am a bit of a MATLAB novice. Any assistance would be greatly appreciated.

 Akzeptierte Antwort

Matt J
Matt J am 28 Nov. 2022

0 Stimmen

fcn=@(f)interp1(f, linspace(1,numel(f),101) );
for i=1:numel(TrajXLstance)
TrajXLstance(i) = structfun(fcn, TrajXLstance(i),'uni',0);
end

6 Kommentare

Josh Tome
Josh Tome am 28 Nov. 2022
This is great! Thank you. Can I ask what the "f" represents?
Josh Tome
Josh Tome am 28 Nov. 2022
Sorry for the 2nd question before you answer the 1st, but I have another structure array similar to the OP, but instead of 1 x ? double arrays it has 3 x ? double arrays. When I try the same code, instead of interpolating the ? number, it interpolates the 3, so I end up with double arrays of size 101 x ?. Any thoughts?
Can I ask what the "f" represents?
It represents the value of a struct field.
When I try the same code, instead of interpolating the ? number, it interpolates the 3
Transpose:
fcn=@(f)interp1(f.', linspace(1,numel(f),101) ).';
Josh Tome
Josh Tome am 28 Nov. 2022
when I use the transpose on the 3 x ? double arrays at first glance it appeared to work by creating arrays of 3 x 101. However, looking closely at these arrays it compressed the actual data by half, and then filled the rest of the 101 points with NAN's. For instance a 3 x 66 array of data was converted into a 3 x 33 array of data with the last 3 x 68 array of NANs. Any idea why that would happen?
Try this insead,
fcn=@(f)interp1(f.', linspace(1, size(f,2) ,101) ).';
Josh Tome
Josh Tome am 29 Nov. 2022
Yes, that seems to work. Thanks again for your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 28 Nov. 2022

Kommentiert:

am 29 Nov. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by