필터 지우기
필터 지우기

obtain 300 values from 840 values

조회 수: 1 (최근 30일)
Anastasia
Anastasia 2018년 8월 19일
답변: Image Analyst 2018년 8월 19일
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
Anastasia
Anastasia 2018년 8월 19일
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 2018년 8월 19일
Have a look on interp1.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2018년 8월 19일
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]);

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by