How to shift an array in graph x-axis with a certain value?
11 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
KSSV
on 13 Apr 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
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!