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

10 次查看(过去 30 天)
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

回答(1 个)

KSSV
KSSV 2022-4-13
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 个评论
Ayberk Ay
Ayberk Ay 2022-4-13
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'

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by