Comparison between 3D maps

7 ビュー (過去 30 日間)
Federico Paolucci
Federico Paolucci 2022 年 12 月 23 日
コメント済み: Federico Paolucci 2022 年 12 月 24 日
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')
Federico Paolucci
Federico Paolucci 2022 年 12 月 24 日
perfect, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface 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