Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Converting/interpolating into different array

조회 수: 2 (최근 30일)
C
C 2011년 6월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
I'm trying to figure out how to convert a 25 unit array into a 10 unit array, while interpolating (not sure if that's actually the right word for this) to make sure that the 10 unit array has the correct values. Any help would be greatly appreciated, thanks!

답변 (2개)

Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 6월 24일
Are you sure is not the other way around? Moving from a 10 element array to a 25 element array you would be interpolation. Moving from a 25 element array to a 10 element array would be decimation.
For decimation:
% Original array
originalArray = 1:25;
% Wished number of samples.
targetSamples = 10;
% Decimation factor.
decimationFactor = length(originalArray)/targetSamples;
decimationFactor = round(decimationFactor); % Decimation factor must be integer.
% Decimation
decimatedArray = decimate(originalArray, decimationFactor);
EDIT
The problem is that DECIMATE allows only integer decimation factors, which not always give you the wished number of samples. Another alternative is the following:
% Original array
originalArray = 1:25;
% Wished number of samples.
targetSamples = 10;
decimatedArray = linspace(originalArray(1), originalArray(end), targetSamples);
Try it and let me know if it works.
  댓글 수: 4
Walter Roberson
Walter Roberson 2011년 6월 24일
It might work for consecutive values, but it isn't going to work for (e.g.) originalArray = (1:25).^2;
C
C 2011년 6월 27일
This does work but the numbers I'm working with are not consecutive...

Walter Roberson
Walter Roberson 2011년 6월 24일
You could use interp1() and play with the interpolation methods that are available.
If the values represent a "signal" then you could fft(), drop components, and fft() the reduced array back.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by