Filter löschen
Filter löschen

Equate two data sets by smoothing larger and decreasing its data points

2 Ansichten (letzte 30 Tage)
Lia Kirtadze
Lia Kirtadze am 24 Aug. 2022
Beantwortet: Hari am 5 Sep. 2023
Hello
I have two matrix and they do not have same number of elements, I need to make them as to have equal number of elements and is it possible by some kinf of smoothing ?
I do not want to randomly delete elements from one data set
Thanks in advance
  1 Kommentar
Mathieu NOE
Mathieu NOE am 30 Aug. 2022
hello
maybe the best option is to make the smaller one the same size as the larger one (instead of shrinking the large one)
this can be done by using interp1 or interp2 (depends if you process 1D or 2D arrays)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Hari
Hari am 5 Sep. 2023
Hi,
As per my understanding, you want to equate two matrices with a different number of elements without randomly deleting elements.
You can use interpolation or resampling techniques to achieve this. These techniques allow you to estimate or interpolate missing values in a matrix based on the available data.
Approach-1: Using interpolation.
Interpolation methods in MATLAB, such as interp1, interp2, or interp3, allow you to estimate values at arbitrary locations within the range of the original data. These are used to fill in the gaps between discrete data points to obtain a continuous representation of the data.
Here's an example of how you can do interpolation by using “interp1” function in MATLAB. This makes the matrices to have an equal number of elements by estimating the values which are falling short:
% Interpolate matrix1 to match the desired number of elements
interpolatedMatrix1 = interp1(linspace(0, 1, numel(matrix1)), matrix1, linspace(0, 1, desiredNumElements));
% Interpolate matrix2 to match the desired number of elements
interpolatedMatrix2 = interp1(linspace(0, 1, numel(matrix2)), matrix2, linspace(0, 1, desiredNumElements));
Approach-2: Using resampling.
The resample function performs resampling by changing the sample rate of the matrix, effectively changing the number of elements while preserving the shape and characteristics of the data.
Here is an example code for resampling:
% Resample matrix1 to match the desired number of elements
resampledMatrix1 = resample(matrix1, desiredNumElements, numel(matrix1));
% Resample matrix2 to match the desired number of elements
resampledMatrix2 = resample(matrix2, desiredNumElements, numel(matrix2));
Refer to the documentation to learn more about interpolation.
Refer to the documentation to learn more about resampling.

Community Treasure Hunt

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

Start Hunting!

Translated by