obtain 300 values from 840 values

1 visualización (últimos 30 días)
Anastasia
Anastasia el 19 de Ag. de 2018
Respondida: Image Analyst el 19 de Ag. de 2018
Hello everybody,
I have one column S with 840 values. I would like to ultimately obtain 300 values because I would like to do a correlation analysis with another column containing 300 values. What would be the formula to use to do that? Could I do an average from several values, and how could I write that?
Thank you!
  4 comentarios
Anastasia
Anastasia el 19 de Ag. de 2018
Thank you. Actually, I would like for the signal with the 300 values to be as close as possible from the signal from the 840 values. Either I would use every third value but I would have 280 values in the end, so I thought, as you mentioned, generate a kind of moving average that would ultimately give me 280 values, but I do not know how to do that. Thank you for your help.
KSSV
KSSV el 19 de Ag. de 2018
Have a look on interp1.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 19 de Ag. de 2018
Anastasia, you still haven't specified what you want, so here is one guess. I just interpolate between all the points and uniformly sample the 300 points between the first point and the last point:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Make 840 random values
numPoints = 840
period = 100;
x = 1 : numPoints;
v = 3 * cos(2 * pi * x / period) + rand(1, numPoints);
% Get 300 "x" values
xq = linspace(1, length(v), 300);
v300 = interp1(x, v, xq);
% Plot everything
subplot(3, 1, 1);
plot(x, v, 'b.-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;
title('840 Points', 'FontSize', fontSize);
subplot(3, 1, 2);
plot(xq, v300, 'ro', 'LineWidth', 2, 'MarkerSize', 7);
grid on;
title('300 Points', 'FontSize', fontSize);
% Smooth the signal
vSmooth = conv(v, ones(1, 15), 'same');
% Get 300 "x" values
xq = linspace(1, length(v), 300);
vs300 = interp1(x, vSmooth, xq);
subplot(3, 1, 3);
plot(xq, vs300, 'ro', 'LineWidth', 2, 'MarkerSize', 7);
grid on;
title('300 Smoothed Points', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);

Community Treasure Hunt

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

Start Hunting!

Translated by