Data Interpolation using interp1

2 次查看(过去 30 天)
Hi
I am trying to interpolate different data sets, so that they all have the same size for my further analysis.
maxLength = max([length(unique_expperimental_dis), length(unique_experimental_force), length(abaqus_force)]);
xFit = 1:maxLength;
experimental_dis_interp = interp1(1:length(unique_expperimental_dis), unique_expperimental_dis, xFit);
size('experimental_dis_interp')
experimental_force_interp = interp1(1:length(unique_experimental_force), unique_experimental_force, xFit);
size('experimental_force_interp')
abaqus_force_interp = interp1(1:length(abaqus_force), abaqus_force, xFit);
size('abaqus_force_interp')
But wenn I read out the sizes of the different data sets, they do not match eachother. Any suggestions what I am doing wrong?
Barbara

采纳的回答

Walter Roberson
Walter Roberson 2020-12-8
编辑:Walter Roberson 2020-12-8
maxLength = max([length(unique_expperimental_dis), length(unique_experimental_force), length(abaqus_force)]);
xFit = 1:maxLength;
experimental_dis_interp = interp1(1:length(unique_expperimental_dis), unique_expperimental_dis, xFit);
size(experimental_dis_interp)
experimental_force_interp = interp1(1:length(unique_experimental_force), unique_experimental_force, xFit);
size(experimental_force_interp)
abaqus_force_interp = interp1(1:length(abaqus_force), abaqus_force, xFit);
size(abaqus_force_interp)
You were calculating the size() of the character vectors, not the variables.
Caution: you have not turned on extrapolation, so the above code is equivalent to padding the short vectors with NaN.
  2 个评论
Barbara Schläpfer
Barbara Schläpfer 2020-12-8
Thank you for your quick answer. Do I understand that right, that I will have to change my xFit ?
Walter Roberson
Walter Roberson 2020-12-11
If padding with NaN was not your intention, then you need to be more clear about your desired outcome.
If you have two variables in which there is a linear relationship between the two, so (say) 2/3 of the way through the range of one should correspond to 2/3 of the way through the range of the other, then you can scale between them:
fraction_through_first_range = (value_in_first_range - minimum_of_first_range) / (maximum_of_first_range - minimum_of_first_range);
projected_into_second_range = minimum_of_second_range + (maximum_of_second_range - mininum_of_second_range) * fraction_through_first_range
Is it really the number of different entries in a group that matters to you, or are you wanting to project by portion of the way through the respective range?
linspace(unique_expperimental_dis(1), unique_expperimental_dis(end), maxLength)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by