Why do I have two waveforms in my plot while I should have only one?

2 次查看(过去 30 天)
I import a matrix from CST and plot 2 columns and get two different waveforms. Why is this happening since x and y are 360x1 columns?
  1 个评论
Mathieu NOE
Mathieu NOE 2023-12-12
even if you data is 1D this could be a concatenation of two measurements , so you would also get 2 lines
make sure you have unique x and y
or maybe you already made a first plot with hold on and you still have this first trace

请先登录,再进行评论。

回答(1 个)

Sandeep Mishra
Sandeep Mishra 2024-9-6
Hi Dimakopoulos,
I noticed from the attached screenshot that you have two input vectors, x and y, each of size 360x1, resulting in two waveforms on your plot.
This situation often arises when the dataset used in the plot function contains duplicate value.
For instance, consider the following example:
x=[1,2,3,4,5,7,5,4,3,2];
y=[1,2,2,3,4,7,6,5,4,2];
plot(x,y)
In this example, the point (2,2) is repeated, which can cause the plot to appear as if there are two waveforms.
To address this issue, you can remove the duplicate pairs of values from your dataset using the approach below:
% Pairing x and y values
xy = [x', y'];
% Find unique (x,y) pairs
[unique_xy, unique_indices] = unique(xy, 'rows', 'stable');
% Extract the unique x and y values
x_unique = unique_xy(:, 1);
y_unique = unique_xy(:, 2);
% Plotting the unique points
plot(x_unique, y_unique)
Please refer to the below documentation to learn more about ‘uniquefunction in MATLAB: https://www.mathworks.com/help/releases/R2020b/matlab/ref/double.unique.html
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by