obtain 300 values from 840 values
Mostrar comentarios más antiguos
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
Image Analyst
el 19 de Ag. de 2018
Editada: Image Analyst
el 19 de Ag. de 2018
WE don't know the formula. Just how are these 300 values to be arrived at? Taken randomly from the 840 values? Use the first 300? Take a moving average of some values? Use every other value? We have no idea, but surely you must have some idea as to how to generate these 300 values. Tell us.
KALYAN ACHARJYA
el 19 de Ag. de 2018
Editada: KALYAN ACHARJYA
el 19 de Ag. de 2018
@Image Analyst sir Can apply interp1?? or Zero Padding?
Anastasia
el 19 de Ag. de 2018
KSSV
el 19 de Ag. de 2018
Have a look on interp1.
Respuestas (1)
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]);

Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!