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

조회 수: 3 (최근 30일)
dimakopoulos alexandros
dimakopoulos alexandros 2023년 12월 12일
답변: Sandeep Mishra 2024년 9월 6일
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에서 Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by