Borrar filtros
Borrar filtros

How to shift an array in graph x-axis with a certain value?

11 visualizaciones (últimos 30 días)
Ayberk Ay
Ayberk Ay el 13 de Abr. de 2022
Editada: Ayberk Ay el 13 de Abr. de 2022
I have two arrays, these arrays have 1050000 elements between 0-360 (in order). I need a shift difference between the arrays. I've tried to make that diff with adding an array '+30' but this value effects the y axis on graph and make the array up on graph. I need that '30 value' to make the one array right shift in x-axis on graph. Also, i don't know the what x-axis is on my graph. Is there a default x-axis for the arrays like time? I just simply use 'plot(array)' to see the graph. Hope you can understand this situation.
P.S : that difference should not affect only the graph, but also should be like 'r2 - r1 = 30', i want to use the difference for my code. Maybe there is a different way to use that diff value except 'r2 - r1 = 30'
a = 0;
b = 360;
rng('shuffle');
ncycles = 10;
npoints = 1050000;
r1 = sort((b-a)*rand(npoints/ncycles,ncycles)+a,1,'ascend');
r1 = r1(:);
sigmas = 5;
randomNoise = randn(length(r1), 1)*sigmas+a;
r11 = r1 + randomNoise;
r2 = r1 + 30;
plot(r2);
hold on
plot(r11);
hold off

Respuestas (1)

KSSV
KSSV el 13 de Abr. de 2022
Add 30 to the x-values i.e. to the indices.
a = 0;
b = 360;
rng('shuffle');
ncycles = 10;
npoints = 1050000;
r1 = sort((b-a)*rand(npoints/ncycles,ncycles)+a,1,'ascend');
r1 = r1(:);
sigmas = 5;
randomNoise = randn(length(r1), 1)*sigmas+a;
r11 = r1 + randomNoise;
r2 = r1 ;
plot((1:length(r2))+30,r2); %<---- 30 added to x-values
hold on
plot(1:length(r11),r11);
hold off
  1 comentario
Ayberk Ay
Ayberk Ay el 13 de Abr. de 2022
It didn't work for me. There is no difference. Btw I forgot to mention that this difference should not only affect only the graph, but also should be like 'r2 - r1 = 30', i want to use the difference for my code. Maybe there is different way to use that diff value except 'r2 - r1 = 30'

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by