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

8 vues (au cours des 30 derniers jours)
Ayberk Ay
Ayberk Ay le 13 Avr 2022
Modifié(e) : Ayberk Ay le 13 Avr 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

Réponses (1)

KSSV
KSSV le 13 Avr 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 commentaire
Ayberk Ay
Ayberk Ay le 13 Avr 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'

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by