Changing order of plot?
12 views (last 30 days)
Show older comments
Emil Doyle
on 5 Feb 2021
Answered: David Coventry
on 5 Feb 2021
I'm trying to plot a set of data. This is my code:
clc
clear
close all
stat = importdata("static pressure.txt");
dir = importdata("direction.txt");
tot = importdata("total pressure.txt");
cp_cfd = (stat-tot)/(0.5*0.8*36.3^2);
plot(dir/0.1524,-cp_cfd,'r','.');
But, since direction.txt is not ordered for smallest to largest, the plot comes out like this (the plot function doesn't automatically order it):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/510642/image.png)
I would like it to look like this (this is a scatter plot and I drew in a line in paint to show what I would like it to look like):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/510647/image.png)
How would I do this?
0 Comments
Accepted Answer
David Coventry
on 5 Feb 2021
You can likely sort the direction, and use the sorted index to reorder the y values.
See the documentation of sort for more information
[x, I] = sort(dir/0.1524);
y = -cp_cfd(I);
plot(x,y,'r')
0 Comments
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!