How to plot a smooth curve while data point order is messed up

1 visualización (últimos 30 días)
MJ
MJ el 23 de Nov. de 2022
Comentada: Image Analyst el 23 de Nov. de 2022
First thanks for spending your precious time on my question.
I have a data set in a double, for example:
0.141176470588235 87.0369747899159
0.403235294117645 258.710588235294
0.354117647058822 230.757647058823
0.329117647058822 207.584537815126
0.297647058823528 184
0.244411764705881 159.604705882352
0.216176470588234 141.458823529411
0.216176470588234 119.623529411764
Countinous data..
16.0094117647058 240.645133689839
16.9411764705882 224.443208556149
17.5341176470588 213.138823529411 (n-1 th data point)
0.60000000000000 326.800000000000 (n th data points)
as you can see the order is messed up, and plotted curve looks messed up as well..
For example, the curve connects n th data points and n-1 th data point, making a kind of loop
I can easily re-order them but the problem is these data points were imported from excel spreadsheet and needs lots of time to separate them.
So I just decided to import whole spreadsheet, upto 102 columns with many blanks (recorded as NaN).
What would be the best way to plot it?

Respuesta aceptada

Voss
Voss el 23 de Nov. de 2022
Editada: Voss el 23 de Nov. de 2022
Some random data:
data = randn(10,2)
data = 10×2
-1.0678 -1.5150 -0.5278 -0.0481 0.5504 -0.7380 0.2118 -0.7771 -1.1406 -0.6477 2.1720 0.2623 1.5867 -0.3605 -1.8863 0.3281 0.2803 0.4477 0.3407 0.8607
Sort on the first column:
[~,idx] = sort(data(:,1));
data = data(idx,:)
data = 10×2
-1.8863 0.3281 -1.1406 -0.6477 -1.0678 -1.5150 -0.5278 -0.0481 0.2118 -0.7771 0.2803 0.4477 0.3407 0.8607 0.5504 -0.7380 1.5867 -0.3605 2.1720 0.2623
Then plot with the new data.
  2 comentarios
MJ
MJ el 23 de Nov. de 2022
I truly appreciate you Voss!
You definitely saved my time.
I wish you a great day.
Image Analyst
Image Analyst el 23 de Nov. de 2022
@MJ I was also going to suggest sorting. So if this solves the question for you then please click the "Accept this answer" link to award @Voss "reputation points" for the answer. Thanks in advance. 🙂

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by