How to remove unwanted double image in plot

Hi Fellas
I created this plot from a text file I imported into matlab, and I am not sure why the plot looks like it has these extra lines on it, particularly one going straight from the starting point to the end poin on the graph. I am not sure why this plot has this issue, as I looked through the text file and all of the numbers seem correct. The plot was originally generated using a network analyzer on an antenna, and no double lines were originally present. I have also not seen this issue with any of the other plots I have made in matlab. Any info on what could be the issue is appreciated. I have attached the matlab code file and the s parameter data below.

 채택된 답변

Matt J
Matt J 2026년 4월 25일 23:34

0 개 추천

It is possible your points are not sorted in ascending order of x.

댓글 수: 7

Blayze
Blayze 2026년 4월 25일 23:45
Not sure what you mean by ascending order.
Check that your data is sorted by calling issorted on the variable you're using as the X coordinates of your plot.
x = [1 2 3 4 5];
issorted(x, 'ascend') % true, x is in increasing order
ans = logical
1
y = [1 2 3 4 5 1];
issorted(y, 'ascend') % false, y(6) is greater than y(5)
ans = logical
0
Matt J
Matt J 2026년 4월 26일 1:32
편집: Matt J 2026년 4월 26일 1:34
plot() connects your (x,y) points in whatever order they are listed, so, if they are not listed in consecutive order, you get things like this:
x=circshift(linspace(-1,0.75,50),-1);
y=x.^2;
plot(x,y,'-o'); axis padded
Blayze
Blayze 2026년 4월 26일 1:36
>> issorted(Simulated_data_elements_unconnected_frequency,'ascend')
ans =
logical
0
Blayze
Blayze 2026년 4월 26일 1:37
Hmm it does look like that the x values are not in ascending order. Do you know how to check where the discontinuity is?
Let's make some sample data:
x = [1 2 3 4 3 4 5 1]
x = 1×8
1 2 3 4 3 4 5 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ind = find(x(2:end) <= x(1:end-1))
ind = 1×2
4 7
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
check = [x(ind); x(ind+1)].'
check = 2×2
4 3 5 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x(4) [the first element of ind] is indeed greater than x(5), as the first row of check shows. Similarly x(7) is greater than x(8) as shown in the second row of check.
Blayze
Blayze 2026년 4월 26일 3:59
편집: Blayze 2026년 4월 26일 4:00
Thanks for the help everyone, it looks like one of the text files contained multiple sets of data, which is why the functions kept indicating the data for the x values was not always increasing. The plot now contains no extraneous lines.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2026년 4월 26일 3:38

1 개 추천

Try something like this with your data
[sortedx, sortOrder] = sort(x, 'ascend'); % Sort x and get the order it was sorted in.
sortedy = y(sortOrder); % Sort y the same way so the y stays matched up with its original x.
plot(sortedx, sortedy, 'b-', 'LineWidth', 2); % Plot the sorted data.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2026년 4월 25일 22:54

편집:

2026년 4월 26일 4:00

Community Treasure Hunt

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

Start Hunting!

Translated by