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.
Steven Lord
Steven Lord 2026 年 4 月 26 日 0:08
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?
Steven Lord
Steven Lord 2026 年 4 月 26 日 2:03
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.

カテゴリ

質問済み:

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