I am trying to plot Column 4 against Column 10 as a line plot, but only when Columns 8 and 9 are between 0 +/- 0.0005. (Columns 8, 9, 10 are x, y, and z locations).
I would have done this with two if loops which would print the row if the conditions were met. This could have then been plotted. I feel as there are over 400,000 entries this is inefficient (file attached represents a smaller quantity due to size constraints). Prealloaction is not possible as I don't know the size of the final array. What would the best way to go about this?

2 Kommentare

Walter Roberson
Walter Roberson am 1 Jan. 2020
In the cases where the conditions are not met, what do you want to do? Are you wanting to do a scatter plot? Are you wanting to plot a disconnected line segment for each consecutive area where the conditions are met? Are you wanting to create a single line plot as if the entries that do not met the condition were not present at all ?
JLV
JLV am 1 Jan. 2020
I do not want to use the data at all where the conditions mentioned above is not met.
A scatter plot with a line of best fit will be plotted (Column4 vs Column10).

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

per isakson
per isakson am 1 Jan. 2020
Bearbeitet: per isakson am 1 Jan. 2020

1 Stimme

See Indexing with Logical Values half way down the page
A starter
%%
M = dlmread('matrix.txt');
%%
is_show = abs(M(:,8))<5e-4 & abs(M(:,9))<5e-4;
%%
figure
plot( M(is_show,10), M(is_show,4), '.' )

3 Kommentare

Very useful, reminds me logic plays an important role in coding rather than if and for loops. Thanks.
A follow up here
What would be the best way to plot Column4 if:
is_show = abs(M(:,10))<5e-4
I am trying to plot M(is_show,4) against its respective x and y coordinate locations M(is_show,8) and M(is_show,9), similar to a filled 2D contour plot. I have tried scatter too with no avail. Any suggestions on plot type will be useful.
Walter Roberson
Walter Roberson am 2 Jan. 2020
Bearbeitet: per isakson am 3 Jan. 2020
x = M(is_show,8);
y = M(is_show,9);
z = M(is_show,4);
Finterp = scatteredInterpolant(x, y, z);
xmin = min(M(:,8));
xmax = max(M(:,8));
ymin = min(M(:,9));
ymax = max(M(:,9));
N = 500;
xrange = linspace(xmin, xmax, N);
yrange = linspace(ymin, ymax, N);
[XGrid, YGrid] = meshgrid(xrange, yrange);
ZGrid = Finterp(XGrid, YGrid);
contourf(XGrid, YGrid, ZGrid);
xlabel('M 8');
ylabel('M 9');
zlabel('M 4');
JLV
JLV am 4 Jan. 2020
I will take a look into this and the code deeper when Im back in the office.
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2019b

Tags

Gefragt:

JLV
am 1 Jan. 2020

Kommentiert:

JLV
am 4 Jan. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by