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 Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by