Comparison between 3D maps

조회 수: 6 (최근 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 CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by