Building a series of 2D black and white graphs in MATLAB

I am trying to build a series of 2D matrices containing those and zeros (effectively black and white images) in MATLAB that are ordered in 3D.

The code I have so far is:

function PlotthreeD()

 numrows = 100;
 numcols = 100;

 Plot1 = zeros(numcols);
 Plot1(20:50,20:50) = 1;

 Plot2 = zeros(numcols);
 Plot1(20:70,20:90) = 1;

 Plot3 = zeros(numcols);
 Plot3(20:50,20:50) = 1;

         B = cat(3, Plot1, Plot2, Plot3);

 figure; 
 offset = 100;
 hold on; 

 for i=1:3; 
     mesh(B(:,:,i)+offset*(i));
 end

end

Is there a drawing command (not a grid) that will allow me to display 2D arrays as solid shapes (where the matrix elements are 1), instead of making these areas appear raised (as they are with the grid)

+3
source share
4 answers

This will be done:

numrows = 100;
numcols = 100;
close all;

Plot1 = zeros(numcols);
Plot1(20:50,20:50) = 1;

Plot2 = zeros(numcols);
Plot2(20:70,20:90) = 1;

Plot3 = zeros(numcols);
Plot3(20:50,20:50) = 1;

B = cat(3, Plot1, Plot2, Plot3);
B(B==0)=NaN;

figure;
offset = 100;
hold on;

for i=1:3;
    surf(B(:,:,i)+offset*(i)); 
end
+1
source

Explore the Matlab imagesc () function

0
source

pcolor . , , :

shading - faceted, . C .

So you can add an extra row and column of zeros to your matrix by adding from 1 to numrowsand numcols.

Here is a sample code from the documentation:

pcolor(hadamard(20))
colormap(gray(2))
axis ij
axis square

alt text

0
source

SPY is also a good way to view binary matrices.

0
source

Source: https://habr.com/ru/post/1734786/


All Articles