Rearrange halves of yaxis in graph

조회 수: 1 (최근 30일)
vanrapa
vanrapa 2019년 4월 24일
편집: vanrapa 2020년 3월 24일
Hello,
I need to rearrange my graph. I would like to rearrange the y axis so that, y for x=1.25 to 2.1 will be placed before the y values of x = 0 to 1.25. But there shouldn't be any change in the xaxis. I don't think I can use 'fliplr' for this. But I am not able to figure out the code to do this through indexing.
Pls help me.

채택된 답변

Adam Danz
Adam Danz 2019년 4월 24일
편집: Adam Danz 2019년 4월 24일
If I understand correctly, move the section of data from x=1.25 to x=2.1 and place that segment just before x=0.
Assuming you have two variables x & y that were used to plot your data: plot(x,y),
segmentStart = 1.25;
segmentStop = 2.1;
placeBefore = 0;
newIdx = [...
find(x<min(placeBefore, segmentStart)), ... %index values prior to insertion point
find(x>=segmentStart & x<=segmentStop), ... %index values of segment to be moved
find(x>=0 & x<segmentStart), ... %index values of section between insertion point and start of segement
find(x>segmentStop),... %indes values following the segment
];
plot(x, y(newIdx))
  댓글 수: 1
vanrapa
vanrapa 2019년 4월 25일
Works perfectly. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thorsten
Thorsten 2019년 4월 24일
편집: Thorsten 2019년 4월 24일
i = find(x == 1.25);
y = y([i+1:end, 1:i]);
  댓글 수: 1
Adam Danz
Adam Danz 2019년 4월 24일
편집: Adam Danz 2019년 4월 24일
This assumes the x values contain the discrete value of 1.25. If there data are x=[..., 1.246, 1.251, ...] this will break. It also asumes the data start with x=0 and end with x=2.1.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by