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

조회 수: 12 (최근 30일)
Ayberk Ay
Ayberk Ay 2022년 4월 13일
편집: Ayberk Ay 2022년 4월 13일
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