There is a way to stretch (scale) for a scaling factor a curve and save the stretched indexes and corresponding values ?
Show older comments
I stretched the value and the length of a vector for a scaling factor. Now I would like to save the new stretched indices and values? can I do that
Answers (1)
Walter Roberson
on 22 Apr 2022
If what you have currently is a list of x coordinates and a list of y coordinates, and you want the same density, then it would sound like you would just do
new_x = x .* x_scale;
new_y = y .* y_scale;
If you have a list of x and y coordinates, and the x is equally sampled and monotonic, and you want to increase the density, then the lazy way is to
new_length = round(length(x) * x_scale);
x_query = linspace(x(1), x(end), new_length);
y_query = interp1(x, y, x_query);
new_x = x_query .* x_scale;
new_y = y_query .* y_scale;
If the x is not equally sampled, or x is not monotonic, then I suggest you look in the File Exchange for John D'Errico's interp_arc(), scale the input x and input y first, and then interp_arc() on those.
2 Comments
Paola
on 22 Apr 2022
Walter Roberson
on 22 Apr 2022
Sure you could put them in the same vector.
combined_vector = [new_x, new_y];
However that will not be of any benefit to you.
If you need to xcorr then get the current x coordinates for the longer vector, scale down by the x stretching factor, and use those as query points in interp1(shorter_x, shorter_y, query_points) . Then take the resulting y and apply the y stretching factor to them . Now you xcorr those results against the y for the longer vector.
[If the stretched vector is to be compared to a vector that has fewer points, it is best to reverse roles of the two, so that you use the longer length as the ones being xcorr()'d )
Categories
Find more on Descriptive Statistics and Insights in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!