Why do I have two waveforms in my plot while I should have only one?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Mathieu NOE
il 12 Dic 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
Risposte (1)
Sandeep Mishra
il 6 Set 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 ‘unique’ function in MATLAB: https://www.mathworks.com/help/releases/R2020b/matlab/ref/double.unique.html
I hope this helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!