Comparison between 3D maps

6 次查看(过去 30 天)
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

采纳的回答

Karim
Karim 2022-12-23
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 个评论
Image Analyst
Image Analyst 2022-12-23
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')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by