Add noise to discrete time series
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andrea
el 28 de Feb. de 2015
Respondida: Image Analyst
el 28 de Feb. de 2015
Hi,
I have a long-term time series composed by discrete labels,the values are 1,2,3,4.
Now, I want to add noise to these time series changing in randomly position the value of the label.
I need to pass the percentage of the data to change (for ex. 5% or 10%), evaluate randomly the positions to change and change the value in the positions selected.
Example:
input: [11122323444442343211] % 20 elements
Add noise for 10 % = 2 elements...
select randomly positions of 2 elements and change the value
output: [11142323441442343211]
Thanks in advance.
Andrea
0 comentarios
Respuesta aceptada
Image Analyst
el 28 de Feb. de 2015
Try this rather straightforward approach using randperm():
inputValues = [1,1,1,2,2,3,2,3,4,4,4,4,4,2,3,4,3,2,1,1] % 20 elements
% Find out how many elements 10% of our input vector is.
elementsToChange = round(0.1 * length(inputValues))
% Randomly choose that many locations to change the value of.
indexesToChange = randperm(length(inputValues), elementsToChange)
outputValues = inputValues; % Initialize
% Get new values for the indexes that we want to change.
newValues = randi(4, 1, length(indexesToChange))
% Assign those values to the locations we selected.
outputValues(indexesToChange) = newValues
Let me know if there is anything you don't follow or understand.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Mathematics and Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!