Comparison between 3D maps

6 Ansichten (letzte 30 Tage)
Federico Paolucci
Federico Paolucci am 23 Dez. 2022
Hello, I would like some advice on this: I have two 3D matrices A and B, 221x101x100 in size. They are matrices composed of elements 0 and 1 (they are binary matrices). I would like to make a comparison between the two matrices in the 4 cases
A B
0 0
0 1
1 0
1 1
then, I have to plot the four cases with different colours. thanks for tha advice

Akzeptierte Antwort

Karim
Karim am 23 Dez. 2022
Hello, you could use the scatter function to plot a sphere for the values that are true. Note, you need to use the ind2sub function if you want to obtain the 3D coordinates.
% set up random binary matrices...
A = rand(221,101,100) > 0.975;
B = rand(221,101,100) > 0.975;
% perform the comparison
A1B1 = A & B;
A0B1 = ~A & B;
A0B0 = ~A & ~B;
A1B0 = A & ~B;
% set up scatter points for 3D plot, using the indices as x,y,z values
[X,Y,Z] = ind2sub(size(A1B1),find(A1B1));
figure
scatter3(X,Y,Z,'filled')
title('A = 1 & B = 1')
grid on
view(3)
  2 Kommentare
Image Analyst
Image Analyst am 23 Dez. 2022
If you want them all on the same plot, it gets a bit messy, especially for large arrays, but here is all of them for a much smaller array.
% set up random binary matrices...
A = rand(5,5,10) > 0.5;
B = rand(5,5,10) > 0.5;
% perform the comparison
A1B1 = A & B;
A0B1 = ~A & B;
A0B0 = ~A & ~B;
A1B0 = A & ~B;
% For A == 1 and B == 1
% set up scatter points for 3D plot, using the indices as x,y,z values
[X,Y,Z] = ind2sub(size(A1B1),find(A1B1));
scatter3(X,Y,Z, 10, 'r', 'filled')
title('Color Coded Pairs')
grid on
view(3)
hold on;
% For A == 0 and B == 1
[X,Y,Z] = ind2sub(size(A0B1),find(A0B1));
scatter3(X,Y,Z, 10, 'g', 'filled')
% For A == 1 and B == 0
[X,Y,Z] = ind2sub(size(A1B0),find(A1B0));
scatter3(X,Y,Z, 10, 'b', 'filled')
% For A == 0 and B == 0
[X,Y,Z] = ind2sub(size(A0B0),find(A0B0));
scatter3(X,Y,Z, 10, 'm', 'filled')
legend('A=1, B=1', 'A=0, B=1', 'A=1, B=0', 'A=0, B=0')
Federico Paolucci
Federico Paolucci am 24 Dez. 2022
perfect, thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by