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

2 visualizaciones (últimos 30 días)
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 comentario
Mathieu NOE
Mathieu NOE el 12 de Dic. de 2023
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

Iniciar sesión para comentar.

Respuestas (1)

Sandeep Mishra
Sandeep Mishra el 6 de Sept. de 2024
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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by