How to plot entire row of numerical matrix from corresponding logical array?

3 views (last 30 days)
I have a 176496x3 double numerical matrix (A) comprised of 3D coordinate point data. I used the 'ischange' function on matrix A - the output is a 176496x3 logical matrix (A_changed). From there I isolated the nonzero points and was given a 467x1 logical matrix (A_nonzero).
The 467 nonzero values correspond to 467 values detected by the 'ischange' funtion. The values are not full coordinate points.
How can I plot (on a 3D plane), not just the 467 individual coordinates, but the entire rows (xyz-coordinate/3D point) that they come from?
An example of what I mean:
A =
[0.220, 0.0095, -0.2745;
0.2210, 0.009, -0.2744;
0.2218, 0.009, -0.2745;
0.2215, 0.0095, -0.2744;
0.2215, 0.0085, -0.2743]
A_changed =
[0, 0, 0;
0, 1, 1;
0, 1, 0;
1, 0, 1;
0, 0, 1]
A_nonzero =
[1;
1;
1;
1;
1;
1]
In this example, I want to plot
A_final =
[0.2210, 0.009, -0.2744;
0.2218, 0.009, -0.2745;
0.2215, 0.0095, -0.2744;
0.2215, 0.0085, -0.2743]
Additionally, here is the code I'm using:
% The data is imported from a file titled Drill
A = Drill;
A_changed = ischange(A, 'linear', 'Threshold', 0.01);
B = A_changed > 0;
A_nonzero = A_changed(B);
Attached is a small sample of the data (100 points). I made sure there are at least 5 rows with values detected by the 'ischange' function. I can also provide the full set of data as an .xyz file if that is preferred.
Lastly, I'm using Matlab R2021a.

Accepted Answer

Kevin Holly
Kevin Holly on 2 Oct 2021
Drill = [ 0.2324 0.0010 -0.2805
0.2324 0.0005 -0.2805
0.2322 0 -0.2800
0.2324 0 -0.2805
0.2325 0.0005 -0.2806
0.2325 0.0010 -0.2808
0.2325 0 -0.2809
0.1840 0.0046 -0.2640
0.1840 0.0050 -0.2643
0.1835 0.0050 -0.2640
0.1850 0.0050 -0.2643
0.1845 0.0051 -0.2645
0.1845 0.0050 -0.2642
0.1850 0.0051 -0.2645
0.1852 0.0050 -0.2645
0.1841 0.0045 -0.2640
0.1845 0.0045 -0.2642
0.1850 0.0045 -0.2642
0.1855 0.0045 -0.2641
0.1855 0.0047 -0.2645
0.2266 0.0005 -0.2760
0.2250 0 -0.2756
0.2255 0 -0.2758
0.2260 0 -0.2759
0.2265 0 -0.2760
0.2265 0 -0.2760
0.2278 0 -0.2760
0.1618 0.0040 -0.2570
0.1620 0.0040 -0.2568
0.1620 0.0041 -0.2570
0.1600 0.0050 -0.2577
0.1600 0.0055 -0.2577
0.1595 0.0050 -0.2575
0.1595 0.0055 -0.2577
0.1616 0.0045 -0.2575
0.1620 0.0045 -0.2573
0.1620 0.0047 -0.2575
0.1600 0.0045 -0.2576
0.1595 0.0045 -0.2575
0.1613 0.0040 -0.2575
0.2315 -0.0045 -0.2780
0.2320 -0.0042 -0.2780
0.2318 -0.0045 -0.2775
0.2320 -0.0043 -0.2775
0.2315 -0.0045 -0.2780
0.2317 -0.0040 -0.2780
0.2315 -0.0050 -0.2775
0.2315 -0.0045 -0.2780
0.2315 -0.0045 -0.2780
0.2320 -0.0042 -0.2785
0.2320 -0.0042 -0.2790
0.1320 0.0019 -0.2480
0.1320 0.0020 -0.2482
0.1316 0.0020 -0.2480
0.1342 0.0020 -0.2485
0.1340 0.0020 -0.2480
0.1341 0.0020 -0.2480
0.1340 0.0021 -0.2485
0.1325 0.0017 -0.2480
0.1325 0.0020 -0.2482
0.2331 -0.0215 -0.2780
0.2330 -0.0220 -0.2777
0.2330 -0.0222 -0.2775
0.2333 -0.0215 -0.2785
0.2334 -0.0210 -0.2785
0.2335 -0.0210 -0.2787
0.2335 -0.0207 -0.2785
0.2340 -0.0210 -0.2788
0.2340 -0.0205 -0.2785
0.2335 -0.0215 -0.2789
0.2335 -0.0216 -0.2785
0.0508 0 -0.2170
0.0510 0 -0.2166
0.0510 0.0003 -0.2170
0.0515 0 -0.2168
0.0515 0.0002 -0.2170
0.0517 0 -0.2170
0.0505 0.0001 -0.2175
0.0505 0 -0.2174
0.0510 0.0004 -0.2175
0.2333 -0.0355 -0.2720
0.2322 -0.0360 -0.2720
0.2325 -0.0357 -0.2720
0.2330 -0.0356 -0.2720
0.2215 -0.0560 -0.3115
0.2215 -0.0559 -0.3115
0.2215 -0.0560 -0.3114
0.2216 -0.0560 -0.3115
0.2215 -0.0559 -0.3120
0.2215 -0.0560 -0.3120
0.2220 -0.0560 -0.3116
0.2220 -0.0557 -0.3120
0.2025 -0.0595 -0.3165
0.2025 -0.0595 -0.3165
0.2025 -0.0595 -0.3165
0.2030 -0.0595 -0.3163
0.2030 -0.0594 -0.3165
0.2034 -0.0595 -0.3165
0.2040 -0.0595 -0.3163
0.2040 -0.0595 -0.3160];
% The data is imported from a file titled Drill
A = Drill;
A_changed = ischange(A, 'linear', 'Threshold', 0.01);
% B = A_changed > 0;
row(:,1) = sum(A_changed,2);
row(:,2) = 1:length(row);
rows2plot = row(row(:,1)>0,:);
figure
subplot(1,3,1)
plot3(A(rows2plot(:,2),1),A(rows2plot(:,2),2),A(rows2plot(:,2),3))
subplot(1,3,2)
scatter3(A(rows2plot(:,2),1),A(rows2plot(:,2),2),A(rows2plot(:,2),3),'r','filled')
subplot(1,3,3)
plot3(A(rows2plot(:,2),1),A(rows2plot(:,2),2),A(rows2plot(:,2),3))
hold on
scatter3(A(rows2plot(:,2),1),A(rows2plot(:,2),2),A(rows2plot(:,2),3),'r','filled')
  2 Comments
Marina Baltz
Marina Baltz on 2 Oct 2021
This worked perfectly, thank you! If you don't mind though, can you please explain what this part of the code is doing?
row(:,1) = sum(A_changed,2);
row(:,2) = 1:length(row);
rows2plot = row(row(:,1)>0,:);
Just trying to better my understanding for the future :)
Kevin Holly
Kevin Holly on 2 Oct 2021
The first line sums the rows and saves the vertical vector to the first column of variable row
row(:,1) = sum(A_changed,2);
by default sum(A_changed), would sum the columns;
sum(A_changed,1) also sums the columns;
I created an index for each of the orignal rows, naming them 1,2,3,4....until I reach the last index position (in this case is 100), which is equal to the length(row) or size(row,1). I could have also made it the length(A_changed) or size(A_changed,1).
row(:,2) = 1:length(row);
Next, I converted that sumed vertical vector that may have values greater than 1 (could be 2 or 3) to a logical array of ones and zeros.
row(:,1)>0
I used that logical array to select the rows I will use.
rows2plot = row(row(:,1)>0,:);
logical_array = row(:,1)>0
row(row_selection,column_selection)
the colon (:) selects all points
logical array selects all points with value of 1 (true)
so you can view it as:
rows2plot = row(logical_array,:)
rows2plot =
1 41
1 52
1 61
2 72
2 81

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!